【问题标题】:wpf Wizard Toolkit validation after click next点击下一步后wpf Wizard Toolkit验证
【发布时间】:2014-12-04 13:59:27
【问题描述】:

我正在使用 wpf 扩展工具包中的向导控件,但现在我遇到了问题。这是我的看法:

<xctk:Wizard Width="300" Height="300" HelpButtonVisibility="Collapsed" FinishButtonVisibility="Visible" Name="wizard" Next="wizard_Next">
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Next">
        <mvvm:EventToCommand Command="{Binding NextCommand}" PassEventArgsToCommand="True"/>
    </i:EventTrigger>
</i:Interaction.Triggers>
<xctk:WizardPage x:Name="Step1Page" PageType="Blank" CanSelectNextPage="{Binding CanGoNext}" FinishButtonVisibility="Collapsed">
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>

        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" FontSize="14" Foreground="Red" Text="Log in to Vodafone One Net"/>
        <StackPanel Grid.Row="1" Margin="0,15,0,0">
            <TextBlock  Text="Step 1" FontWeight="SemiBold"/>
            <TextBlock  Text="Please enter your mobile number"/>
        </StackPanel>
        <xctk:WatermarkTextBox Grid.Row="2" Name="mobileNumber" PreviewKeyDown="OnPreviewKeyDown" AcceptsReturn="False" AcceptsTab="False" Watermark="Enter mobile number" Text="{Binding MobileNumber}"  Margin="0,10,0,0">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TextChanged">
                    <i:InvokeCommandAction Command="{Binding MobileNumberTextChangedCommand}" CommandParameter="{Binding ElementName=mobileNumber, Path=Text}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>

            <i:Interaction.Behaviors>
                <v:AllowableCharactersTextBoxBehavior RegularExpression="^\d+$" MaxLength="50" />
            </i:Interaction.Behaviors>
        </xctk:WatermarkTextBox>

    </Grid>
</xctk:WizardPage>

....

然后在带有 CanGoNext 的 ViewModel 中,我进行了一种验证,以便用户可以继续下一步或不继续(取决于文本框是否填充了某些内容)。

当用户单击下一步时,我会进行 REST 调用以验证号码,如果号码不是有效号码,我不想转到第 2 步,但向导总是会转到第 2 步。

我什至尝试在我的 RelayCommand 中传递 CancelRoutedEventArgs:

public async Task Next(CancelRoutedEventArgs e)
{
    var resp = await this._requestService.PostRequestPin(this.MobileNumber);

    if (resp.StatusCode == ERROR)
    {
        e.Cancel = true;
        e.Handled = true;
    }

}

用户总是转到第 2 步。有人知道我该怎么做吗?

谢谢。 问候,

【问题讨论】:

    标签: c# wpf mvvm mvvm-light wizard


    【解决方案1】:

    找到了解决办法。这太容易了。

    RelayCommand CanExecute 方法可以满足我的需求。很容易,也有很多时间去那里!

    【讨论】:

    • 您能详细解释一下吗?如果将事件“Next”的 InteractionTrigger 添加到向导中,下一个按钮是否使用 CanExecute?
    • 是的。当您定义 RelayCommand 的第二个参数 (CanExecute) 时,您可以拥有一个执行所有验证并返回 true 或 false 的方法。
    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 2023-03-18
    • 2017-12-17
    • 2018-02-02
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    相关资源
    最近更新 更多