Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Mark validation errors on visual element #83

Conversation

nicolaihenriksen
Copy link
Contributor

This PR is not production ready, it is more a proof-of-concept for a feature request.

The feature request originates from my PR in the MaterialDesignInXaml project. See the last paragraph regarding the TODOs left in the UI tests.

Idea
When writing a unit test for a control in isolation (as opposed to a test for some UI using the control), it would be cool to be able to force a validation error in order to assert that some conditions are met when a validation error is present. Ideally this could be done using the XAMLTest library instead of having to wire up a real ValidationRule on a binding in the XAML under test, and also having to "force" the UI into a state where the validation error occurs. All that is - IMO - simply boiler-plate code that I would rather not write in my UI tests.

Proposed solution
Extend the XAMLTest library with MarkInvalid(DP, string), ClearInvalid(DP), and GetValidationErrorContent(DP) which can be used to bring an element into an "error state" (i.e. Validation.HasError = true), clear the "error state" from an element, and get the error content from an element respectively.

I must admit I do not have years of experience with the built-in validation scheme, so there may be some quirks/drawbacks to this approach that I am missing.

I have added some tests as well to illustrate the potential use for this.

@nicolaihenriksen nicolaihenriksen changed the title Feature validation errors Feature request: Mark validation errors on visual element Aug 17, 2022
@Keboo Keboo force-pushed the featureValidationErrors branch from 2bc2298 to 4ffc2bc Compare August 17, 2022 22:14
@Keboo Keboo closed this Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants