WPF enable next button of Wizard on Validation success

Using a wizard in my application that validates the input. The user must not be able to move to the next page if the validation is not a success. This can be done by disabling the next button when validation failes. The NextButtonEnabled property is hooked to the Validation.HasError property of the inputcontrol. Code sample below.

<wizard:WizardPage x:Name="WizardPage">
    <!--Style that sets the NextButtonEnabled based on validation-->            
        <Style TargetType="wizard:WizardPage">
                <DataTrigger Binding="{Binding ElementName=DataControl,Path=(Validation.HasError), UpdateSourceTrigger=PropertyChanged}" Value="True">
                    <Setter Property="NextButtonEnabled" Value="False" />
    <!--Input controls-->
        <TextBox Name="DataControl">
                <Binding Path="MyValue" UpdateSourceTrigger="PropertyChanged" >
                        <my:NotNullOrEmptyValidationRule ErrorMessage="Supply data"/>

This doesn’t cover the user directly clicking the next button, but that is handled by the check in the Unselecting eventhandler.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.