This project has moved. For the latest updates, please go here.

Conditional Wizard Pages

Sep 30, 2014 at 2:54 PM
Hi there,
I'm new to wpf and the extended wpf toolkit.
I need to write a wizard where the next page depends on some conditions, evaluated in the code backend.
Is there an easy way to accomplish this. I've tried something like:
NextPage="{Binding SomeString}"
but it doesn't seem to work.
Thank You in advance for any help.
Mateusz
Developer
Sep 30, 2014 at 7:14 PM
Hi,

You can use the WizardPage.CanNextPage property and set it when your conditions are filled :
 <xctk:WizardPage x:Name="_page"
                          PageType="Interior"
                          Title="Page 2"
                          Description="This is the second page in the process"
                          CanSelectNextPage="False">
            <Button Content="Test"
                    Click="Button_Click" />
</xctk:WizardPage>

 private void Button_Click( object sender, RoutedEventArgs e )
    {
      if( _page != null )
      {
        _page.CanSelectNextPage = true;
      }
    }
Sep 30, 2014 at 8:20 PM
Hi,
That's not what I was exactly looking for.
I need different pages to be displayed depending on some conditions.
Thanks for the effort though.
Mateusz
Developer
Oct 1, 2014 at 12:08 PM
Hi,

How about modifying the currentPage when the button Next is pressed :
<xctk:Wizard x:Name="_wizard"
                   FinishButtonClosesWindow="True"
                   Help="OnWizardHelp"
                   Next="Wizard_Next">
         <xctk:WizardPage x:Name="_page1"
                          Title="Welcome to my Wizard"
                          Description="This Wizard will walk you though how to do something." />
         <xctk:WizardPage x:Name="_page2"
                          PageType="Interior"
                          Title="Page 1"
                          Description="This is the first page in the process." />
         <xctk:WizardPage x:Name="_page3"
                          PageType="Interior"
                          Title="Page 2"
                          Description="This is the second page in the process" />
         <xctk:WizardPage x:Name="_page4"
                          PageType="Interior"
                          Title="Last Page"
                          Description="This is the last page in the process"
                          CanFinish="True" />
</xctk:Wizard>

private void Wizard_Next( object sender, Toolkit.Core.CancelRoutedEventArgs e )
    {
      var wizard = sender as Xceed.Wpf.Toolkit.Wizard;
      if( wizard != null )
      {
        if( wizard.CurrentPage == _page1 )
        {
          //wizard.CurrentPage = _page3;
          //or
          wizard.CurrentPage = wizard.Items[ 2 ] as WizardPage;
        }
      }
    }
Oct 1, 2014 at 1:13 PM
Edited Oct 1, 2014 at 1:14 PM
Hi,
I've actually found a solution.
You can set
SomeWizardPage.NextPage = ConditionToEvaluate ? OnTrueWizardPageName : OnFalseWizardPageName;
in the code backend.
Hope this saves somebody else's time.
Mateusz
Dec 8, 2014 at 6:09 PM
Hi,

is there any way to set NextPage via binding in XAML? I would like to have radio buttons with basic actions, and show next pages according to selected action...
I cannot find right way how to do that.

Jaroslav
Developer
Dec 9, 2014 at 2:34 PM
Hi,

How about using the binding in the Tag property of the RadioButtons and using the the Checked event to set the WizardPage.NextPage to the RadioButton's Tag :
<xctk:Wizard x:Name="_wizard"
                      FinishButtonClosesWindow="True">
            <xctk:WizardPage Title="Welcome to my Wizard"
                             Description="This Wizard will walk you though how to do something.">
               <StackPanel>
                  <RadioButton x:Name="RadioButton1"
                               Content="Go To FirstPage"
                               Checked="RadioButton_Checked"
                               Tag="{Binding ElementName=Page1}"/>
                  <RadioButton x:Name="RadioButton2"
                               Content="Go To SecondPage"
                               Checked="RadioButton_Checked"
                               Tag="{Binding ElementName=Page2}"/>
               </StackPanel>
            </xctk:WizardPage>
            <xctk:WizardPage x:Name="Page1"
                             PageType="Interior"
                             Title="Page 1"
                             Description="This is the first page in the process."/>
            <xctk:WizardPage x:Name="Page2"
                             PageType="Interior"
                             Title="Page 2"
                             Description="This is the second page in the process" />
            <xctk:WizardPage PageType="Interior"
                             Title="Last Page"
                             Description="This is the last page in the process"
                             CanFinish="True" />
</xctk:Wizard>

 private void RadioButton_Checked( object sender, RoutedEventArgs e )
    {
      RadioButton button = ( sender as RadioButton );
      WizardPage wizardPage = this.FindVisualParent<WizardPage>( button ) as WizardPage;
      wizardPage.NextPage = button.Tag as WizardPage;
    }

    public T FindVisualParent<T>( DependencyObject child ) where T : DependencyObject
    {
      // get parent item
      DependencyObject parentObject = VisualTreeHelper.GetParent( child );

      // we’ve reached the end of the tree
      if( parentObject == null )
        return null;

      // check if the parent matches the type we’re looking for
      T parent = parentObject as T;
      if( parent != null )
      {
        return parent;
      }
      else
      {
        // use recursion to proceed with next level
        return FindVisualParent<T>( parentObject );
      }
 }
Dec 11, 2014 at 8:21 PM
That's exactly what I needed!
Thank you very much,

Jaroslav