【问题标题】:WPF toolkit wizard access controls from the pages in my codeWPF 工具包向导从我的代码中的页面访问控件
【发布时间】:2015-01-13 20:24:40
【问题描述】:

在我的 XAML 文件中,我有一个这样定义的向导

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

然后,我有 2 或 3 个页面和一些控件来请求用户输入。

我想禁用下一步按钮,直到文本输入被填满,并且我想在向导完成后访问字段中的信息。

我尝试设置我的输入控件的 x:Name 属性,然后可能对它们做一些事情,但我无法在我的代码中访问它们。

【问题讨论】:

    标签: c# wpf wpftoolkit


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多