WPF toolkit wizard access controls from the pages in my code

2.5k views Asked by At

In my XAML file, I have a Wizard defined like this

<Window.Resources>
    <xctk:Wizard x:Key="wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">

Then, I have a 2 or 3 pages and a few controls to request input from the user.

I would like to disable the next button until the text inputs are filled and I would like to access the information from the fields once the wizard is done.

I tried setting the x:Name property of my input controls and then maybe do something with those but I cannot access them in my code anyway.

1

There are 1 answers

0
bogza.anton On

In WizardPage you need Bind CanSelectNextPage property to boolean property in code behind

Example:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
        Title="MainWindow" Height="350" Width="525" x:Name="Window">
    <Window.Resources>
        <xctk:Wizard x:Key="Wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">
            <xctk:WizardPage CanSelectNextPage="{Binding ElementName=Window, Path=CanSelectNext}">
                <StackPanel>
                    <Label Content="Label1"/>
                    <Button Content="Click Me" Click="ButtonBase_OnClick"/>
                </StackPanel>
            </xctk:WizardPage>
            <xctk:WizardPage>
                <Label Content="Label2"/>
            </xctk:WizardPage>W
        </xctk:Wizard>
    </Window.Resources>
    <Grid>
    <ContentPresenter Content="{StaticResource Wizard}"/>
    </Grid>
</Window>

Code Behind:

public partial class MainWindow : INotifyPropertyChanged
    {

        ...

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            CanSelectNext = true;
            OnPropertyChanged("CanSelect");    
        }

        public bool CanSelectNext { set; get; }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        ...
    }