-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathIsNullOrEmptyStateTrigger.bind
94 lines (89 loc) · 4.31 KB
/
IsNullOrEmptyStateTrigger.bind
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
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:triggers="using:Microsoft.Toolkit.Uwp.UI.Triggers"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TextBoxStates">
<VisualState x:Name="TextBoxNotEmptyState" />
<VisualState x:Name="TextBoxEmptyState">
<VisualState.StateTriggers>
<triggers:IsNullOrEmptyStateTrigger Value="{Binding Text, ElementName=OurTextBox, Mode=OneWay}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="OurTextBox.BorderBrush" Value="Red" />
<Setter Target="OurTextBoxError.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ListBoxStates">
<VisualState x:Name="ListNotEmptyState" />
<VisualState x:Name="ListEmptyState">
<VisualState.StateTriggers>
<triggers:IsNullOrEmptyStateTrigger Value="{Binding Items, ElementName=OurList, Mode=OneWay}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="RemoveButton.IsEnabled" Value="False" />
<Setter Target="ListEmptyMessage.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ListViewStates">
<VisualState x:Name="SelectedItemNotNullState" />
<VisualState x:Name="SelectedItemNullState">
<VisualState.StateTriggers>
<triggers:IsNullOrEmptyStateTrigger Value="{Binding SelectedItem, ElementName=SelectList}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="RemoveSelection.IsEnabled" Value="False" />
<Setter Target="SelectionEmptyMessage.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="The TextBox below will warn if it is empty." />
<StackPanel Orientation="Horizontal" Margin="0 0 0 20">
<TextBox x:Name="OurTextBox" Text="" Width="200" />
<TextBlock x:Name="OurTextBoxError" Text="* Required" Foreground="Red" Margin="10 0 0 0" Visibility="Collapsed" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,40,0,0">
<Button x:Name="AddButton" Content="Add" Margin="0 0 10 0"/>
<Button x:Name="RemoveButton" Content="Remove"/>
</StackPanel>
<TextBlock x:Name="ListEmptyMessage" Text="List is empty, add some items" Visibility="Collapsed"/>
<ListBox x:Name="OurList" HorizontalAlignment="Left">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="3" />
<Setter Property="Margin" Value="3" />
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Border BorderBrush="Gold" BorderThickness="1" Margin="0,80,0,0" Width="275">
<StackPanel>
<Button x:Name="RemoveSelection" Content="Deselect" />
<TextBlock x:Name="SelectionEmptyMessage" Text="SelectedItem is empty, select an item" Visibility="Collapsed"
Margin="5,0,0,0"/>
<ListView x:Name="SelectList" HorizontalAlignment="Left">
<ListView.Items>
<TextBlock Text="One" />
<TextBlock Text="Two" />
<TextBlock Text="Three" />
</ListView.Items>
</ListView>
</StackPanel>
</Border>
</StackPanel>
</Grid>
</Page>