Open VBAndCs opened 4 years ago
+1 on this as well, coming from MVC, I find it very weird not having out of the box support for Data Annotation validation. I feel like this is one of the spots where WPF/XAML could really use some love.
I am skeptical on this one. Where would you use these? A lot of the attributes seem really web-centric.
Hey, it's been a while, I am just learning WPF and landed on this issue, I think it may be a good time to ask if anything changed and for some other ways to reuse that attribute validation logic?
Nothing changed as far as I know. You could create a ValidationRule
that reads any ValidationAttribute
s on the target and validates the value against them.
The attributes are in a separate assembly that WPF would have to introduce a dependency on, I am not sure that is a realistic expectation at the moment.
I suggest that you allow using the attributes defined in System.ComponentModel.DataAnnotations with any property in a wpf project, like ASP.NET does. For example:
ASP.NET generates server side validation code for these attributes (beside the client side validation scripts), so, I think you can make WPF borrow the class that generates the server side code to achieve this. Note: There are some attributes used with tag helpers to affect the UI such as DisplayAttribute. I think XAML should also add the tag helpers concept too. I find it easier and shorter than the currently used data binding.