spiegelp / MaterialDesignExtensions

Material Design Extensions is based on Material Design in XAML Toolkit to provide additional controls and features for WPF apps
https://spiegelp.github.io/MaterialDesignExtensions/
MIT License
762 stars 122 forks source link

Step Validation Preventing Backwards Navigation #62

Closed AmitBhatnagar24 closed 4 years ago

AmitBhatnagar24 commented 4 years ago

I'm again adding to this once closed issue because I still feel that I don't know exactly to handle the validation,

When I have a 2 Step stepper with BlockNavigationOnValidationErrors set to true. I have derived from Step to allow for validation as per the documents. If I reach step 2 and it fails validation.. why would it prevent me from going back a step? I feel that the BlockNavigationOnValidationErrors should only restrict going to the next step.

How can I accomplish this with the already implemented validation and events/commands already in play?

Originally posted by @AmitBhatnagar24 in https://github.com/spiegelp/MaterialDesignExtensions/issues/4#issuecomment-558943637

spiegelp commented 4 years ago

@AmitBhatnagar24 Navigating back to previous steps even if validation failed could be a reasonable action. I will have a look at the behavior of the stepper and might change it in the next release.

AmitBhatnagar24 commented 4 years ago

thanks @spiegelp

I think it makes sense - can't proceed but shouldn't prevent you from backtracking to a previous step. Is there a way I can accomplish this with what you have currently? When do you expect the next release to happen?

spiegelp commented 4 years ago

@AmitBhatnagar24 You can accomplish the behavior with some own code (have a look into the API doc and the source code for details):

  1. set BlockNavigationOnValidationErrors = false
  2. handle the BackNavigation event or register a BackNavigationCommand
  3. both have a StepperNavigationEventArgs as argument on which you can set Cancel = true to stop the navigation (some kind like args.Cancel = !args.CurrentStep.HasValidationErrors)

I do not have a schedule for the next stable release, but I may publish a pre-release around the mid of December.

spiegelp commented 4 years ago

@AmitBhatnagar24 I did a pre-release with the enhanced behavior some moments ago.