-
Notifications
You must be signed in to change notification settings - Fork 342
/
RequiredStringValidationBehaviorPage.xaml
49 lines (41 loc) · 2.75 KB
/
RequiredStringValidationBehaviorPage.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
<?xml version="1.0" encoding="UTF-8"?>
<pages:BasePage 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"
x:Class="CommunityToolkit.Maui.Sample.Pages.Behaviors.RequiredStringValidationBehaviorPage"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Behaviors"
x:TypeArguments="vm:RequiredStringValidationBehaviorViewModel"
x:DataType="vm:RequiredStringValidationBehaviorViewModel">
<pages:BasePage.Resources>
<Style x:Key="ValidEntryStyle" TargetType="Entry">
<Setter Property="TextColor" Value="Green"/>
</Style>
<Style x:Key="InvalidEntryStyle" TargetType="Entry">
<Setter Property="TextColor" Value="Red" />
</Style>
</pages:BasePage.Resources>
<VerticalStackLayout Padding="{StaticResource ContentPadding}"
Spacing="50"
VerticalOptions="StartAndExpand">
<Label Text="The RequiredStringValidationBehavior is a behavior that allows the user to determine if text input is equal to specific text. For example, an Entry control can be styled differently depending on whether a valid or an invalid text input is provided. Additional properties handling validation are inherited from ValidationBehavior"
TextColor="{StaticResource NormalLabelTextColor}" />
<Label Text="Text color will change accordingly to the style that is configured when a required string is not entered." />
<Entry Placeholder="Required String: 123. Exact match">
<Entry.Behaviors>
<mct:RequiredStringValidationBehavior RequiredString="123"
InvalidStyle="{StaticResource InvalidEntryStyle}"
ValidStyle="{StaticResource ValidEntryStyle}"
Flags="ValidateOnValueChanged"/>
</Entry.Behaviors>
</Entry>
<Entry Placeholder="Required substring: 123">
<Entry.Behaviors>
<mct:RequiredStringValidationBehavior RequiredString="123" ExactMatch="False"
InvalidStyle="{StaticResource InvalidEntryStyle}"
ValidStyle="{StaticResource ValidEntryStyle}"
Flags="ValidateOnValueChanged"/>
</Entry.Behaviors>
</Entry>
</VerticalStackLayout>
</pages:BasePage>