WPF Toolkit Tool Wizard provides access to controls from my code
In my XAML file, I have a Wizard defined as
<Window.Resources>
<xctk:Wizard x:Key="wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">
Then I have 2 or 3 pages and several controls to request input from the user.
I want to disable the next button until the text inputs are complete and I would like to access the information from the fields after completing the wizard.
I tried to set a property x:Name
on my input controls and then maybe do something with them, but I still can't access them in my code.
+3
source to share
1 answer
In WizardPage you need Bind property CanSelectNextPage for 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 for:
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));
}
...
}
0
source to share