WPF工具包向导如何从我的代码页面访问控件

4
在我的XAML文件中,我定义了一个向导,如下所示:
<Window.Resources>
    <xctk:Wizard x:Key="wizard" FinishButtonClosesWindow="True" HelpButtonVisibility="Hidden">

接下来,我有2或3页内容以及一些控件需要从用户那里获取输入。

在文本输入框填写内容之前,我希望禁用下一步按钮,并且在向导完成后可以访问字段中的信息。

我尝试设置我的输入控件的属性,然后可能对它们进行某些操作,但无论如何我都无法在代码中访问它们。

1个回答

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));
        }

        ...
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接