【问题标题】:wpf Wizard Toolkit ItemsSource binding to a Listwpf Wizard Toolkit ItemsSource 绑定到列表
【发布时间】:2018-11-12 21:49:34
【问题描述】:

我正在实现 MVVM 模式并希望使用 WPF 工具包 (Xceed.Wpf.Toolkit) 中的向导控件来设计我的界面。

我想做的是将向导的项目源绑定到List<ViewModelBase> 并使用DataTemplate 将其显示为页面。到目前为止,还没有乔伊。 :-(

我已经尽可能地精简了我的代码,但这就是它的精髓。

我对 XAML 的看法:

<xctk:Wizard FinishButtonClosesWindow="True" ItemsSource="{Binding Pages}" />

我的数据模板:

<DataTemplate DataType="{x:Type vm:ViewModelBase}">
    <xctk:WizardPage Title="{Binding DisplayName}" Description="{Binding DisplayDescription}"/>
</DataTemplate>

在cs文件中: 虚拟机,返回列表的属性被定义:

public List<ViewModelBase> Pages

在 app.xaml.cs 中:

var viewModel = new ViewModels.winMainViewModel();
winMain window = new winMain();

window.DataContext = viewModel;
window.Show();

抛出的错误是:

System.NotSupportedException 未处理 HResult=-2146233067
Message=Wizard 应该只包含 WizardPages。
Source=Xceed.Wpf.Toolkit

任何帮助将不胜感激。

TIA, 雷

【问题讨论】:

    标签: c# wpf wpftoolkit toolkit xceed


    【解决方案1】:

    感谢您的回复。 昨晚我尝试玩 IConverter 类但没有运气(还)

    由于截止日期待定,我决定编写一个简单的转换属性。

        public List<WizardPage> wizPages
        {
            get
            {
                List<WizardPage> rtn = new List<WizardPage>();
                foreach (ViewModelBase vmb in Pages)
                {
                    rtn.Add(new WizardPage()
                    {   Title = vmb.DisplayName
                    ,   Description = vmb.DisplayDescription
                    ,   DataContext = vmb
                    });  //  rtn.Add
                }   //  foreach (ViewModelBase vmb in Pages)
    
                return rtn;
            }
        }
    

    【讨论】:

      【解决方案2】:

      这显然不受支持,您可以在源代码中看到:https://github.com/xceedsoftware/wpftoolkit/blob/master/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Wizard/Implementation/Wizard.cs

      恐怕你只能绑定到IEnumerable&lt;Xceed.Wpf.Toolkit.WizardPage&gt;

      【讨论】:

        猜你喜欢
        • 2018-02-02
        • 2011-01-14
        • 2011-03-16
        • 2015-04-07
        • 1970-01-01
        • 1970-01-01
        • 2013-01-14
        • 2020-01-30
        • 2015-11-22
        相关资源
        最近更新 更多