The Prism.Validation is based on Prism. It allows you to use Validations based on the ValidationAttributes in your Model, ViewModel and so on. Because most of you want to share your code acroos the .NET application model (also known as App models) the Prism.Validation is shipped as PCL.
Install with nuget Install-Package Prism.Validation
- In you PCL set your Targeting to at least .NETStandard 1.4
- Install Prism.Validation in your project with nuget
Install-Package Prism.Validation
- Create your model class and inherit from
ValidatableBindableBase
. - Decorate your properties with DataAnnotations like
[StringLength(2, ErrorMessage = "Max 2 digits")]
- Set Binding in XAML like
<TextBox Text="{Binding Name,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" />
- For Xamarin.Forms Projects you may check out https://www.davidbritch.com/2017/03/validating-user-input-in-xamarinforms-iv.html
Model classes are a good example which can be used to share across different platforms. Also you may want to add some basic validations into the model with DataAnnotaions.
The Prism Core Libary doesn't provide a validation implementation, so the Prism.Validation libary is filling this gap. The validation was taken over from the UWP ValidatableBindableBase with litte adjustments.
With the Prism.Validation you could share your model with DataAnnotaion between wpf, xamarin and uwp.
With [StringLength(2, ErrorMessage = "Max 2 digits")]
- Upgraded to Prism 7.1.0.431
- Upgraded to Prism 7.0.0.396
- Replaced Portable Data Annotations with System.ComponentModel.Annotations
- Changed Prism.Validation PCL to portable45-net45+win8
- #4 Fixed by using System.ComponentModel.Annotations
- #5 Upgrade packages to Prism 6.2
- #3 Rename Prism.Extensions to Prism.Validation enhancement
- Init (The validation was taken over from the UWP ValidatableBindableBase with litte adjustments.)
- Used Portable Data Annotations
Contribute if you want.