From 6ca56aefe2a1c8c8e33eca9ef036e95aadac8bcd Mon Sep 17 00:00:00 2001 From: luismts Date: Tue, 17 Aug 2021 00:01:12 -0400 Subject: [PATCH] Example 6 added --- .../ValidationRulesTest.csproj | 3 ++ .../ViewModels/Example6ViewModel.cs | 30 ++++++++++++++ .../ValidationRulesTest/Views/Example6.xaml | 41 +++++++++++++++++++ .../Views/Example6.xaml.cs | 38 +++++++++++++++++ .../ValidationRulesTest/Views/Examples.xaml | 5 +++ .../Views/Examples.xaml.cs | 5 +++ 6 files changed, 122 insertions(+) create mode 100644 samples/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs create mode 100644 samples/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml create mode 100644 samples/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml.cs diff --git a/samples/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj b/samples/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj index 4e0385b..b3665f3 100644 --- a/samples/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj +++ b/samples/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj @@ -36,6 +36,9 @@ + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/samples/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs b/samples/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs new file mode 100644 index 0000000..ad57b19 --- /dev/null +++ b/samples/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs @@ -0,0 +1,30 @@ +using Plugin.ValidationRules; +using Plugin.ValidationRules.Extensions; +using Plugin.ValidationRules.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ValidationRulesTest.ViewModels +{ + public class Example6ViewModel + { + public Example6ViewModel() + { + Name = Validator.Build().IsRequired("The name is required."); + Phone = Validator.Build() + .When(x => !string.IsNullOrEmpty(x)) + .Must(x => x.Length == 12, "Minimum lenght is 12."); + + Phone.ValueFormatter = new MaskFormatter("XXX-XXX-XXXX"); + } + + public Validatable Name { get; set; } + public Validatable Phone { get; set; } + + public bool Validate() + { + return Name.Validate() && Phone.Validate(); + } + } +} diff --git a/samples/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml b/samples/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml new file mode 100644 index 0000000..718c515 --- /dev/null +++ b/samples/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + +