3

I am implementing the MVVM pattern and wish to design my interface using the Wizard Control from the WPF ToolKit (Xceed.Wpf.Toolkit).

What I would like to do is bind the Items Source for the Wizard to a List<ViewModelBase> and use a DataTemplate to display it as a page. So far, no Joy. :-(

I have trimmed my code as much as possible but here is the meat of it.

My view XAML:

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

My Data template:

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

In the cs files: the the VM, the property returning the list is defined:

public List<ViewModelBase> Pages

In the app.xaml.cs:

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

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

The error that is thrown is:

System.NotSupportedException was unhandled HResult=-2146233067
Message=Wizard should only contain WizardPages.
Source=Xceed.Wpf.Toolkit

Any help would be greatly appreciated.

TIA, Ray

orhtej2
  • 2,133
  • 3
  • 16
  • 26
Ray Hastie
  • 77
  • 6

2 Answers2

2

Thank you for that response. Last night I tried playing around with an IConverter class with no luck (yet)

Due to pending deadlines, I decided to write a simple conversion property.

    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;
        }
    }
Ray Hastie
  • 77
  • 6
1

This is apparently not supported as you can see in the source code: https://github.com/xceedsoftware/wpftoolkit/blob/master/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Wizard/Implementation/Wizard.cs

I am afraid you can only bind to an IEnumerable<Xceed.Wpf.Toolkit.WizardPage>.

mm8
  • 163,881
  • 10
  • 57
  • 88