WPF 工具包向导从我的代码中的页面访问控制 [英] WPF toolkit wizard access controls from the pages in my code
问题描述
在我的 XAML 文件中,我有一个像这样定义的向导
In my XAML file, I have a Wizard defined like this
<Window.Resources>
<xctk:Wizard x:Key="wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">
然后,我有 2 或 3 个页面和一些控件来请求用户输入.
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.
我尝试设置我的输入控件的 x:Name
属性,然后可能对它们进行一些操作,但无论如何我都无法在我的代码中访问它们.
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.
推荐答案
在 WizardPage 中,您需要将 CanSelectNextPage 属性绑定到后面代码中的布尔属性
In WizardPage you need Bind CanSelectNextPage property to boolean property in code behind
示例:
<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));
}
...
}
这篇关于WPF 工具包向导从我的代码中的页面访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!