-
Notifications
You must be signed in to change notification settings - Fork 338
/
CharactersValidationBehaviorPage.xaml
111 lines (103 loc) · 5.5 KB
/
CharactersValidationBehaviorPage.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?xml version="1.0" encoding="UTF-8"?>
<pages:BasePage x:Class="CommunityToolkit.Maui.Sample.Pages.Behaviors.CharactersValidationBehaviorPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Behaviors"
x:TypeArguments="vm:CharactersValidationBehaviorViewModel"
x:DataType="vm:CharactersValidationBehaviorViewModel">
<pages:BasePage.Resources>
<Style x:Key="InvalidEntryStyle"
TargetType="Entry">
<Setter Property="TextColor" Value="IndianRed" />
</Style>
<Style x:Key="ValidEntryStyle"
TargetType="Entry">
<Setter Property="TextColor" Value="Green" />
</Style>
</pages:BasePage.Resources>
<pages:BasePage.Content>
<VerticalStackLayout
Spacing="25"
VerticalOptions="StartAndExpand">
<Label
Text="Text color will change accordingly to the style that is configured when an invalid string is entered." />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="CharacterType" />
<Picker
x:Name="CharacterTypePicker"
Grid.Row="0"
Grid.Column="1"
Title="CharacterType"
ItemsSource="{Binding CharacterTypes, Mode=OneTime}" />
<Label Grid.Row="1"
Grid.Column="0"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="MinimumCharacterCountEntry" />
<Entry Grid.Row="1" Grid.Column="1"
x:Name="MinimumCharacterCountEntry"
Keyboard="Numeric"
Text="2"
VerticalOptions="FillAndExpand" />
<Label Grid.Row="2"
Grid.Column="0"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="MaximumCharacterCountEntry" />
<Entry Grid.Row="2" Grid.Column="1"
x:Name="MaximumCharacterCountEntry"
Keyboard="Numeric"
Text="20"
VerticalOptions="FillAndExpand" />
</Grid>
<Label Text="Type characters for validation behavior according to the settings you set upon." />
<Entry Placeholder="Type characters...">
<Entry.Behaviors>
<mct:CharactersValidationBehavior
CharacterType="{Binding SelectedItem, Source={x:Reference CharacterTypePicker}}"
Flags="ValidateOnValueChanged"
InvalidStyle="{StaticResource InvalidEntryStyle}"
ValidStyle="{StaticResource ValidEntryStyle}"
MaximumCharacterTypeCount="{Binding Text, Source={x:Reference MaximumCharacterCountEntry}}"
MinimumCharacterTypeCount="{Binding Text, Source={x:Reference MinimumCharacterCountEntry}}" />
</Entry.Behaviors>
</Entry>
<Label Text="The same but styling handled by visual state manager." />
<Entry Placeholder="Type characters...">
<Entry.Behaviors>
<mct:CharactersValidationBehavior Flags="ValidateOnValueChanged"
CharacterType="{Binding SelectedItem, Source={x:Reference CharacterTypePicker}}"
MaximumCharacterTypeCount="{Binding Text, Source={x:Reference MaximumCharacterCountEntry}}"
MinimumCharacterTypeCount="{Binding Text, Source={x:Reference MinimumCharacterCountEntry}}" />
</Entry.Behaviors>
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Valid">
<VisualState.Setters>
<Setter Property="TextColor" Value="Green" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Invalid">
<VisualState.Setters>
<Setter Property="TextColor" Value="IndianRed" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
</Entry>
</VerticalStackLayout>
</pages:BasePage.Content>
</pages:BasePage>