|
1 | 1 | <?xml version="1.0" encoding="UTF-8" ?>
|
2 |
| -<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms" |
| 2 | +<pages:BasePage x:Name="Page" |
| 3 | + x:Class="Xamarin.CommunityToolkit.Sample.Pages.Behaviors.CharactersValidationBehaviorPage" |
| 4 | + xmlns="http://xamarin.com/schemas/2014/forms" |
3 | 5 | xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
4 | 6 | xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
|
5 |
| - xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages" |
6 |
| - x:Name="Page" |
7 |
| - x:Class="Xamarin.CommunityToolkit.Sample.Pages.Behaviors.CharactersValidationBehaviorPage"> |
| 7 | + xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"> |
8 | 8 |
|
9 | 9 | <pages:BasePage.Resources>
|
10 | 10 | <Style x:Key="InvalidEntryStyle"
|
11 | 11 | TargetType="Entry">
|
12 |
| - <Setter Property="TextColor" |
13 |
| - Value="Red" /> |
| 12 | + <Setter Property="TextColor" Value="Red"/> |
| 13 | + </Style> |
| 14 | + |
| 15 | + <Style x:Key="ValidEntryStyle" |
| 16 | + TargetType="Entry"> |
| 17 | + <Setter Property="TextColor" Value="Green"/> |
14 | 18 | </Style>
|
15 | 19 | </pages:BasePage.Resources>
|
16 | 20 |
|
17 | 21 | <StackLayout Padding="{StaticResource ContentPadding}"
|
18 | 22 | Spacing="25"
|
19 | 23 | VerticalOptions="StartAndExpand">
|
20 |
| - <Label Text="Text color will change accordingly to the style that is configured when an invalid string is entered." /> |
| 24 | + <Label Text="Text color will change accordingly to the style that is configured when an invalid string is entered."/> |
21 | 25 | <Frame Margin="{StaticResource ContentPadding}"
|
22 | 26 | CornerRadius="10">
|
23 | 27 | <Grid>
|
24 | 28 | <Grid.RowDefinitions>
|
25 |
| - <RowDefinition Height="Auto" /> |
26 |
| - <RowDefinition Height="Auto" /> |
27 |
| - <RowDefinition Height="Auto" /> |
| 29 | + <RowDefinition Height="Auto"/> |
| 30 | + <RowDefinition Height="Auto"/> |
| 31 | + <RowDefinition Height="Auto"/> |
28 | 32 | </Grid.RowDefinitions>
|
29 | 33 | <Grid.ColumnDefinitions>
|
30 |
| - <ColumnDefinition Width="*" /> |
31 |
| - <ColumnDefinition Width="*" /> |
| 34 | + <ColumnDefinition Width="*"/> |
| 35 | + <ColumnDefinition Width="*"/> |
32 | 36 | </Grid.ColumnDefinitions>
|
33 |
| - <Label Text="CharacterType" /> |
34 |
| - <Picker x:Name="CharacterTypePicker" |
| 37 | + <Label Text="CharacterType"/> |
| 38 | + <Picker x:Name="CharacterTypePicker" Grid.Column="1" |
35 | 39 | Title="CharacterType"
|
36 |
| - Grid.Column="1" |
37 |
| - ItemsSource="{Binding CharacterTypes, |
38 |
| - Source={x:Reference Page}}" |
39 |
| - SelectedIndex="1" /> |
| 40 | + ItemsSource="{Binding CharacterTypes, Source={x:Reference Page}}" |
| 41 | + SelectedIndex="1"/> |
40 | 42 | <Label Grid.Row="1"
|
41 |
| - Text="MinimumCharacterCountEntry" /> |
42 |
| - <Entry x:Name="MinimumCharacterCountEntry" |
43 |
| - Grid.Row="1" |
44 |
| - Grid.Column="1" |
| 43 | + Text="MinimumCharacterCountEntry"/> |
| 44 | + <Entry x:Name="MinimumCharacterCountEntry" Grid.Row="1" Grid.Column="1" |
45 | 45 | Keyboard="Numeric"
|
46 |
| - Text="2" /> |
| 46 | + Text="2"/> |
47 | 47 | <Label Grid.Row="2"
|
48 |
| - Text="MaximumCharacterCountEntry" /> |
49 |
| - <Entry x:Name="MaximumCharacterCountEntry" |
50 |
| - Grid.Row="2" |
51 |
| - Grid.Column="1" |
| 48 | + Text="MaximumCharacterCountEntry"/> |
| 49 | + <Entry x:Name="MaximumCharacterCountEntry" Grid.Row="2" Grid.Column="1" |
52 | 50 | Keyboard="Numeric"
|
53 |
| - Text="20" /> |
| 51 | + Text="20"/> |
54 | 52 | </Grid>
|
55 | 53 | </Frame>
|
56 |
| - <Label Text="Type characters for validation behavior according to the settings you set upon." /> |
| 54 | + <Label Text="Type characters for validation behavior according to the settings you set upon."/> |
57 | 55 | <Entry Placeholder="Type characters...">
|
58 | 56 | <Entry.Behaviors>
|
59 |
| - <xct:CharactersValidationBehavior CharacterType="{Binding SelectedItem, |
60 |
| - Source={x:Reference CharacterTypePicker}}" |
| 57 | + <xct:CharactersValidationBehavior CharacterType="{Binding SelectedItem, Source={x:Reference CharacterTypePicker}}" |
61 | 58 | InvalidStyle="{StaticResource InvalidEntryStyle}"
|
62 |
| - MaximumCharacterCount="{Binding Text, |
63 |
| - Source={x:Reference MaximumCharacterCountEntry}}" |
64 |
| - MinimumCharacterCount="{Binding Text, |
65 |
| - Source={x:Reference MinimumCharacterCountEntry}}" /> |
| 59 | + ValidStyle="{StaticResource ValidEntryStyle}" |
| 60 | + MaximumCharacterCount="{Binding Text, Source={x:Reference MaximumCharacterCountEntry}}" |
| 61 | + MinimumCharacterCount="{Binding Text, Source={x:Reference MinimumCharacterCountEntry}}"/> |
| 62 | + </Entry.Behaviors> |
| 63 | + </Entry> |
| 64 | + |
| 65 | + <Label Text="The same but styling handled by visual state manager."/> |
| 66 | + <Entry Placeholder="Type characters..."> |
| 67 | + <Entry.Behaviors> |
| 68 | + <xct:CharactersValidationBehavior Flags="ValidateOnValueChanging" |
| 69 | + CharacterType="{Binding SelectedItem, Source={x:Reference CharacterTypePicker}}" |
| 70 | + MaximumCharacterCount="{Binding Text, Source={x:Reference MaximumCharacterCountEntry}}" |
| 71 | + MinimumCharacterCount="{Binding Text, Source={x:Reference MinimumCharacterCountEntry}}"/> |
66 | 72 | </Entry.Behaviors>
|
| 73 | + |
| 74 | + <VisualStateManager.VisualStateGroups> |
| 75 | + <VisualStateGroup x:Name="CommonStates"> |
| 76 | + <VisualState x:Name="Valid"> |
| 77 | + <VisualState.Setters> |
| 78 | + <Setter Property="TextColor" Value="Green"/> |
| 79 | + </VisualState.Setters> |
| 80 | + </VisualState> |
| 81 | + <VisualState x:Name="Invalid"> |
| 82 | + <VisualState.Setters> |
| 83 | + <Setter Property="TextColor" Value="IndianRed"/> |
| 84 | + </VisualState.Setters> |
| 85 | + </VisualState> |
| 86 | + </VisualStateGroup> |
| 87 | + </VisualStateManager.VisualStateGroups> |
67 | 88 | </Entry>
|
| 89 | + |
68 | 90 | </StackLayout>
|
69 | 91 | </pages:BasePage>
|
0 commit comments