-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ValidationExample.xaml
102 lines (89 loc) · 3.71 KB
/
ValidationExample.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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.GalleryPages.VisualStateManagerGalleries.ValidationExample">
<ContentPage.Resources>
<ResourceDictionary>
<Style TargetType="Label" x:Key="ErrorLabel">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="IsVisible" Value="False"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Invalid">
<VisualState.Setters>
<Setter Property="IsVisible" Value="True"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
<Setter Property="TextColor" Value="Red"></Setter>
<Setter Property="Margin" Value="2,10,2,10"></Setter>
</Style>
<Style TargetType="Label" x:Key="FormLabel">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Invalid">
<VisualState.Setters>
<Setter Property="TextColor" Value="DarkRed"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
<Setter Property="Margin" Value="2,10,2,10"></Setter>
</Style>
<Style TargetType="Entry">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Invalid">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightCoral"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<Style TargetType="Editor">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Invalid">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightCoral"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Label Text="Validation Example Form" FontSize="24" HorizontalOptions="Fill" HorizontalTextAlignment="Center" />
<Label x:Name="SubjectLabel" Text="Subject (required):" Style="{StaticResource FormLabel}"></Label>
<Entry x:Name="Subject"></Entry>
<Label x:Name="SubjectError" Style="{StaticResource ErrorLabel}" Text="Invalid subject"></Label>
<Label x:Name="MessageLabel" Style="{StaticResource FormLabel}" Text="Message (40 characters maximum):" ></Label>
<Label x:Name="CharacterCount" Style="{StaticResource FormLabel}"></Label>
<Editor x:Name="Message"></Editor>
<Label x:Name="MessageError" Style="{StaticResource ErrorLabel}" Text="Invalid message"></Label>
<Button x:Name="Submit" Text="Submit" Clicked="Submit_OnClicked"></Button>
<Label Margin="2,20,2,0"
Text="The form above uses the VSM to create a custom 'Invalid' state for the various controls.
When validation runs for the form, it toggles the state of the controls between 'Invalid' and 'Normal',
which determines the appearance of the controls. "></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>