Performing data validation with MVVM
Support for data validation is common in modern development frameworks. If an application or website doesn't alert users about which input fields are invalid, those users will file bug reports, leave bad reviews, or worse… stop using the app/website.
Web developers who use ASP.NET Core, Angular, and React have rich validation support at their disposal. UWP developers have never had built-in support for data validation, but that is changing with the move to WinUI 3.0. Simple validation can be added to our ViewModel
properties through a little boilerplate code and a few attributes.
A little bit of code needs to be added to our BindableBase
class, which is what all the ViewModel
classes will inherit from. This will bring validation support to every ViewModel
. The code for this can be found in the specifications for WinUI: https://github.com/microsoft/microsoft-ui-xaml-specs/blob/user/lucashaines/inputvalidation/active/InputValidation...