ItemsSource Binding on Wizard

Wizard for WPF Forum

Posted 14 years ago by Robert D. Herrick II
Version: 9.2.0514
Avatar
Hello --

I am trying to add WizardPages to a List<WizardPage> and then bind that to ItemsSource. Although the binding seems to work (I get no error), the pages don't show up in the Wizard. Is there something special that I need to do?

My purpose here is to have an overarching ViewModel that controls the page flow, then individual ViewModels for each Page.

Thanks --
Robert

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

Can you make a simple sample project showing this and email it to our support address so we can take a look? Please make sure your ZIP doesn't include any .exe files. Thanks!


Actipro Software Support

Posted 14 years ago by Mark Benda
Avatar
I'm having a similar issue, it seems as if the ItemsSource is filled, just no pages. Did anyone build a small sample?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mark,

We never got a sample from Robert. If you'd like to build one and send it our way, that would be helpful.


Actipro Software Support

Posted 14 years ago by Mark Benda
Avatar
Here's a simple demo of what's going on - just a xaml & c# file - nothing complicated.

<Window x:Class="WizardItemsSourceTest.Window1" Name="WizTester"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    xmlns:wizard="http://schemas.actiprosoftware.com/winfx/xaml/wizard"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="300" Width="500">
    <StackPanel Orientation="Vertical">
        <StackPanel Orientation="Horizontal">
            <Button Content="LoadWizard2" Click="LoadWizard2_Click"/>
        </StackPanel>
        <StackPanel Orientation="Vertical">
            <wizard:Wizard x:Name="wizard1"
                           WindowTitleBaseText="Wizard1 - Load Via ItemSource"
                           ItemsSource="{Binding ElementName=WizTester, Path=WizardPages, diag:PresentationTraceSources.TraceLevel=High}"
                           >
            </wizard:Wizard>
            
            <wizard:Wizard x:Name="wizard2"
                           WindowTitleBaseText="Wizard2 - Load Manually"
                           >                
            </wizard:Wizard>                           
        </StackPanel>
        
        
    </StackPanel>
</Window>
and here's the code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using ActiproSoftware.Windows.Controls.Wizard;
using System.ComponentModel;

namespace WizardItemsSourceTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public List<WizardPage> WizardPages
        {
            get { return (List<WizardPage>)GetValue(WizardPagesProperty); }
            set { SetValue(WizardPagesProperty, value); }
        }

        public static readonly DependencyProperty WizardPagesProperty =
            DependencyProperty.Register("WizardPages", typeof(List<WizardPage>), typeof(Window1), new UIPropertyMetadata(new List<WizardPage>()));


        public Window1()
        {
            InitializeComponent();
            LoadPages();
        }

        private void LoadPages()
        {
            List<WizardPage> wp = new List<WizardPage>();
            for (int x = 0; x < 3; x++)
            {
                WizardPage newPage = new WizardPage();
                newPage.Content = "This is page " + x;
                newPage.MinHeight = 10;
                wp.Add(newPage);
            }

            WizardPages = wp;
        }


        private void LoadWizard2_Click(object sender, RoutedEventArgs e)
        {
            List<WizardPage> wp = new List<WizardPage>();
            for (int x = 0; x < 3; x++)
            {
                WizardPage newPage = new WizardPage();
                newPage.Content = "This is page " + x;
                wizard2.Items.Add(newPage);
            }
        }

    }
}

The error that I'm getting in the output when attempting to bind to the itemssource is:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ActiproSoftware.Windows.Controls.Wizard.Wizard', AncestorLevel='1''. BindingExpression:Path=(0); DataItem=null; target element is 'Grid' (Name='PART_Header'); target property is 'MinHeight' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ActiproSoftware.Windows.Controls.Wizard.Wizard', AncestorLevel='1''. BindingExpression:Path=(0); DataItem=null; target element is 'Grid' (Name='PART_Header'); target property is 'MinHeight' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ActiproSoftware.Windows.Controls.Wizard.Wizard', AncestorLevel='1''. BindingExpression:Path=(0); DataItem=null; target element is 'Grid' (Name='PART_Header'); target property is 'MinHeight' (type 'Double')


It looks as if the errors are internal (unless I'm missing something).
Thanks,
Mark
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mark,

I think due to the order in which you are doing things and also that you are doing a setter on a List property that causes it problems. This will work fine:
public ObservableCollection<WizardPage> WizardPages { get; private set; }

public Window1() {
    this.WizardPages = new ObservableCollection<WizardPage>();

    InitializeComponent();
    LoadPages();
}

private void LoadPages()
{
    for (int x = 0; x < 3; x++)
    {
        WizardPage newPage = new WizardPage();
        newPage.Content = "This is page " + x;
        newPage.MinHeight = 10;
        this.WizardPages.Add(newPage);
    }
}


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.