简体   繁体   中英

wpf Wizard Toolkit validation after click next

I'm using Wizard control from wpf extended toolkit, but right now I'm facing a problem. This is my view:

<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>

....

Then in my ViewModel with the CanGoNext I make a kind of validation so the user can go next or no (depending on if the textbox is filled with something or not).

When the user clicks Next I make a REST call to validate the number, and if the number is not a valid one I don't want to go to step 2, but the wizard is always going to step2.

I even tried to pass the CancelRoutedEventArgs in my RelayCommand doing this:

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

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

}

The user always goes to step2. Anyone with any idea on how I can do ?

Thanks. Regards,

Found the solution. It was soooo easy.

The RelayCommand CanExecute method does what I wanted. So easy and so much time to get there!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM