Matcha.Validation 1.0.1

dotnet add package Matcha.Validation --version 1.0.1
NuGet\Install-Package Matcha.Validation -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Matcha.Validation" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Matcha.Validation --version 1.0.1
#r "nuget: Matcha.Validation, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Matcha.Validation as a Cake Addin
#addin nuget:?package=Matcha.Validation&version=1.0.1

// Install Matcha.Validation as a Cake Tool
#tool nuget:?package=Matcha.Validation&version=1.0.1

Matcha Validation Plugin an Unobtrusive Validation for Xamarin.Forms

A plugin library for unobtrusive "Testable" validation that works well with any MVVM framework , You can create a Customized Rule which perfectly fit to your needs.

Preview

alt text

Get Started

Using ValidationService

With ValidationService you can easily validate the viewmodel that derives from any MVVM framework base viewmodel class, this makes it very powerful and testable at the same time.


public class PrismTabbedPageViewModel : BindableBase
{
	private ValidationService<PrismTabbedPageViewModel> _validationService;

	public PrismTabbedPageViewModel()
	{
		ValidationService = new ValidationService<PrismTabbedPageViewModel>(this);
	}

	public ValidationService<PrismTabbedPageViewModel> ValidationService
	{
		get => _validationService;
		set => SetProperty(ref _validationService, value);
	}
}

ValidationRule<T>

When deriving ValidationRule<T>, this will enables validation of the viewmodels property, The validation could be anything from email, null, greaterthanzero or it could be your custom validation (take EmailRule as an example).


public class IsNotNullOrEmptyRule : ValidationRule<string>
{
	public IsNotNullOrEmptyRule(string propertyName) : base(propertyName)
	{
		ValidationMessage = $"{propertyName} should not be empty!";
	}

	protected override bool CheckValue(string value)
	{
		return IsValid = !string.IsNullOrWhiteSpace(value);
	}
}

Adding the ValidationRule<T> to ValidationService

ValidationRule<T> is a bindable class this what makes the Matcha Validation so powerful because of its pure unobtrusive and it doesnt require custom control to handle it.


public PrismTabbedPageViewModel()
{
	ValidationService = new ValidationService<PrismTabbedPageViewModel>(this);
	EntryNotEmptyRule = ValidationService.Add(e => new IsNotNullOrEmptyRule(nameof(e.UserName))); //
}

Check if all Rule is Valid

ValidationRule<T> is a bindable class this what makes the Matcha Validation so powerful because of its pure unobtrusive and it doesnt require custom control to handle it.


if (ValidationService.IsValid)
{
	//You code here when all rule's are valid
}

XAML Page
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
   x:Class="Sample.Views.PrismTabbedPage"
   xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:converter="clr-namespace:Sample.Converter;assembly=Sample"
   xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
   prism:ViewModelLocator.AutowireViewModel="True">
   <TabbedPage.Resources>
       <ResourceDictionary>
           <converter:InverseBooleanConverter x:Key="BooleanConverter" />
       </ResourceDictionary>
   </TabbedPage.Resources>
   <ContentPage Title="Custom Validation">
       <StackLayout Padding="30">
           <Entry Placeholder="Username" Text="{Binding UserName}" />
           <Label
               FontSize="Micro"
               IsVisible="{Binding EntryNotEmptyRule.IsValid, Converter={StaticResource BooleanConverter}}"
               Text="{Binding EntryNotEmptyRule.ValidationMessage}"
               TextColor="Red" />
           <Button
               Command="{Binding ValidateBuilInCommand}"
               IsEnabled="{Binding ValidationService.IsValid}"
               Text="Validate" />
       </StackLayout>
   </ContentPage>
</TabbedPage>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 4,018 8/27/2018
1.0.0 833 8/27/2018

Change Description