在我的XAML文件中,我有一个像这样定义的向导
<Window.Resources>
<xctk:Wizard x:Key="wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">
然后,我有2或3页和一些控件来请求用户输入。
我想禁用下一个按钮,直到文本输入被填满,并且我想在完成向导后从字段中访问信息。
我尝试设置输入控件的x:Name
属性,然后可能会对这些属性执行某些操作但我无法在代码中访问它们。
答案 0 :(得分:0)
在WizardPage中,您需要将CanSelectNextPage属性绑定到
后面的代码中的布尔属性示例:
<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>
代码背后:
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));
}
...
}