Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samples/Maui/ValidationRulesTest/ValidationRulesTest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidationRulesTest", "Vali
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.ValidationRules", "..\..\..\src\ValidationRules\Plugin.ValidationRules.csproj", "{74CB3C79-59A7-4AAA-A94F-EDA9D278847E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Reactive.ValidationRules", "..\..\..\src\Plugin.Reactive.ValidationRules\Plugin.Reactive.ValidationRules.csproj", "{44FC6F88-FC72-4DC9-B6EB-E76B896A3861}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,6 +25,10 @@ Global
{74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Release|Any CPU.Build.0 = Release|Any CPU
{44FC6F88-FC72-4DC9-B6EB-E76B896A3861}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44FC6F88-FC72-4DC9-B6EB-E76B896A3861}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44FC6F88-FC72-4DC9-B6EB-E76B896A3861}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44FC6F88-FC72-4DC9-B6EB-E76B896A3861}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Plugin.Reactive.ValidationRules\Plugin.Reactive.ValidationRules.csproj" />
<ProjectReference Include="..\..\..\..\src\ValidationRules\Plugin.ValidationRules.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using Plugin.Reactive.ValidationRules;
using Plugin.ValidationRules.Extensions;
using Plugin.ValidationRules.Interfaces;
using Plugin.ValidationRules.Rules;
using ValidationRulesTest.Validations;
using EmailRule = Plugin.ValidationRules.Rules.EmailRule;

namespace ValidationRulesTest.ViewModels
{
public class ReactiveValidationExample1ViewModel : ExtendedPropertyChanged, IDisposable
{
ReactiveValidatable<string> _name;
public ReactiveValidatable<string> Name
{
get => _name;
set => SetProperty(ref _name, value);
}

public ReactiveValidatable<string> _email;
public ReactiveValidatable<string> Email
{
get => _email;
set => SetProperty(ref _email, value);
}

public ReactiveValidatable<string> _password;
public ReactiveValidatable<string> Password
{
get => _password;
set => SetProperty(ref _password, value);
}

public ReactiveValidationExample1ViewModel()
{
Name = new ReactiveValidatable<string>(
string.Empty, new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Name is required"
});

Email = new ReactiveValidatable<string>(string.Empty,
new EmailRule()
{
ValidationMessage = "Email wrongly formatted"
},
new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Email is required"
});

Password = new ReactiveValidatable<string>(string.Empty, new PasswordRule(), new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Password is required"
});
}

public void Dispose()
{
_name?.Dispose();
_email?.Dispose();
_password?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
Clicked="example8_Clicked"
Text="Example 8" />

<Button x:Name="reactiveValidationExample1"
Clicked="ReactiveValidationExample1_Clicked"
Text="Reactive Validation Example" >

</Button>

</StackLayout>
</ContentPage.Content>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ private void example8_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Example8());
}
private void ReactiveValidationExample1_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new ReactiveValidationExample1());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ValidationRulesTest.Views.ReactiveValidationExample1"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:ValidationRulesTest.ViewModels;assembly=ValidationRulesTest"
x:DataType="viewModels:ReactiveValidationExample1ViewModel"
Title="Reactive Validation">

<Grid RowDefinitions="100,100,100,100,*"
Margin="10">

<StackLayout HorizontalOptions="Center"
VerticalOptions="Start">
<Label Text="Reactive Validation Example 1" FontAttributes="Bold"
HorizontalOptions="Center"
FontSize="Large"/>
<Label Text="This example shows how to use ReactiveUI's validation rules to validate a ViewModel."
HorizontalOptions="Center"
Margin="10"
HorizontalTextAlignment="Center"/>
</StackLayout>

<Grid Grid.Row="1"
VerticalOptions="Start"
RowDefinitions="*,Auto">
<Entry Text="{Binding Name.Value, Mode=TwoWay}"
Placeholder="Username"/>
<Label Text="{Binding Name.ErrorMessage}"
Grid.Row="1"
TextColor="Red">
<Label.Triggers>
<DataTrigger Binding="{Binding Name.IsValid}"
Value="False"
TargetType="Label">
<Setter Property="IsVisible" Value="True"/>
</DataTrigger>
<DataTrigger Binding="{Binding Name.IsValid}"
Value="True"
TargetType="Label">
<Setter Property="IsVisible" Value="False"/>
</DataTrigger>
</Label.Triggers>
</Label>
</Grid>

<Grid Grid.Row="2"
VerticalOptions="Start"
RowDefinitions="*,Auto">
<Entry Text="{Binding Email.Value, Mode=TwoWay}"
Placeholder="Email"/>
<Label Text="{Binding Email.ErrorMessage}"
TextColor="Red"
Grid.Row="1">
<Label.Triggers>
<DataTrigger Binding="{Binding Email.IsValid}"
Value="False"
TargetType="Label">
<Setter Property="IsVisible" Value="True"/>
</DataTrigger>
<DataTrigger Binding="{Binding Email.IsValid}"
Value="True"
TargetType="Label">
<Setter Property="IsVisible" Value="False"/>
</DataTrigger>
</Label.Triggers>
</Label>
</Grid>

<Grid Grid.Row="3"
VerticalOptions="Start"
RowDefinitions="*,*">
<Entry Text="{Binding Password.Value, Mode=TwoWay}"
Placeholder="Password"/>
<Label Text="{Binding Password.ErrorMessage}"
TextColor="Red"
Grid.Row="1"
IsVisible="False">
<Label.Triggers>
<DataTrigger Binding="{Binding Password.IsValid}"
Value="False"
TargetType="Label">
<Setter Property="IsVisible" Value="True"/>
</DataTrigger>
<DataTrigger Binding="{Binding Password.IsValid}"
Value="True"
TargetType="Label">
<Setter Property="IsVisible" Value="False"/>
</DataTrigger>
</Label.Triggers>
</Label>
</Grid>
</Grid>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ValidationRulesTest.ViewModels;

namespace ValidationRulesTest.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ReactiveValidationExample1 : ContentPage
{
ReactiveValidationExample1ViewModel _viewModel;

public ReactiveValidationExample1()
{
InitializeComponent();
_viewModel = new ReactiveValidationExample1ViewModel();
BindingContext = _viewModel;
}

protected override void OnDisappearing()
{
_viewModel.Dispose();
base.OnDisappearing();
}
}
}
26 changes: 26 additions & 0 deletions samples/Xamarin.Forms/ValidationRulesTest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidationRulesTest", "Vali
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.ValidationRules", "..\..\src\ValidationRules\Plugin.ValidationRules.csproj", "{1DA953F3-E1A6-425A-B823-629006A45561}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.Reactive.ValidationRules", "..\..\src\Plugin.Reactive.ValidationRules\Plugin.Reactive.ValidationRules.csproj", "{AAC08845-4F44-4851-B512-372380949518}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -159,6 +161,30 @@ Global
{1DA953F3-E1A6-425A-B823-629006A45561}.Release|iPhone.Build.0 = Release|Any CPU
{1DA953F3-E1A6-425A-B823-629006A45561}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{1DA953F3-E1A6-425A-B823-629006A45561}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|iPhone.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|iPhone.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|Any CPU.Build.0 = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|iPhone.ActiveCfg = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|iPhone.Build.0 = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{AAC08845-4F44-4851-B512-372380949518}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -14,10 +14,14 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Plugin.Reactive.ValidationRules\Plugin.Reactive.ValidationRules.csproj" />
<ProjectReference Include="..\..\..\..\src\ValidationRules\Plugin.ValidationRules.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\ReactiveValidationExample1.xaml.cs">
<DependentUpon>ReactiveValidationExample1.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Example1.xaml.cs">
<DependentUpon>Example1.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using Plugin.Reactive.ValidationRules;
using Plugin.ValidationRules.Extensions;
using Plugin.ValidationRules.Interfaces;
using Plugin.ValidationRules.Rules;
using ValidationRulesTest.Validations;
using EmailRule = Plugin.ValidationRules.Rules.EmailRule;

namespace ValidationRulesTest.ViewModels
{
public class ReactiveValidationExample1ViewModel : ExtendedPropertyChanged, IDisposable
{
ReactiveValidatable<string> _name;
public ReactiveValidatable<string> Name
{
get => _name;
set => SetProperty(ref _name, value);
}

public ReactiveValidatable<string> _email;
public ReactiveValidatable<string> Email
{
get => _email;
set => SetProperty(ref _email, value);
}

public ReactiveValidatable<string> _password;
public ReactiveValidatable<string> Password
{
get => _password;
set => SetProperty(ref _password, value);
}

public ReactiveValidationExample1ViewModel()
{
Name = new ReactiveValidatable<string>(
string.Empty, new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Name is required"
});

Email = new ReactiveValidatable<string>(string.Empty,
new EmailRule()
{
ValidationMessage = "Email wrongly formatted"
},
new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Email is required"
});

Password = new ReactiveValidatable<string>(string.Empty, new PasswordRule(), new NotEmptyRule<string>(string.Empty)
{
ValidationMessage = "Password is required"
});
}

public void Dispose()
{
_name?.Dispose();
_email?.Dispose();
_password?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="ValidationRulesTest.Example1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ValidationRulesTest"
Title="Test 1">
<ContentPage x:Class="ValidationRulesTest.Example1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ValidationRulesTest"
Title="Test 1">

<StackLayout Padding="16">

Expand Down
Loading