-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathStateContainerPage.xaml
More file actions
207 lines (183 loc) · 8.66 KB
/
Copy pathStateContainerPage.xaml
File metadata and controls
207 lines (183 loc) · 8.66 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage
x:Class="CommunityToolkit.Maui.Sample.Pages.Layouts.StateContainerPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:layouts="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Layouts"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
x:DataType="layouts:StateContainerViewModel"
x:TypeArguments="layouts:StateContainerViewModel">
<pages:BasePage.ToolbarItems>
<ToolbarItem Command="{Binding ToggleFullPageStateCommand}" Text="Toggle Page" />
</pages:BasePage.ToolbarItems>
<pages:BasePage.Resources>
<Style x:Key="BorderStyle" TargetType="Border">
<Setter Property="Padding" Value="20" />
<Setter Property="StrokeShape" Value="RoundRectangle 10" />
<Setter Property="StrokeThickness" Value="4" />
</Style>
</pages:BasePage.Resources>
<ScrollView>
<VerticalStackLayout
mct:StateContainer.CurrentState="{Binding FullPageState}"
Spacing="12">
<mct:StateContainer.StateViews>
<ContentView
mct:StateView.StateKey="Loading"
mct:StateContainer.CanStateChange="{Binding CanFullPageStateChange}">
<VerticalStackLayout>
<ActivityIndicator
HorizontalOptions="Center"
IsRunning="True"
Color="Fuchsia" />
<Label HorizontalOptions="Center" Text="I'm a state on the whole page!" />
<Label HorizontalOptions="Center" Text="Toggle to go back." />
</VerticalStackLayout>
</ContentView>
</mct:StateContainer.StateViews>
<Label Text="The StateContainer properties allow any Layout derived element to become state-aware." />
<Button Command="{Binding CycleStatesCommand}" Text="Cycle States Without Animation" />
<Label Text="This will show several states at an interval of 2 seconds." />
<Label
FontSize="8"
Text="{Binding CurrentState, StringFormat='Current State: {0}'}"
VerticalTextAlignment="Center" />
<VerticalStackLayout
Padding="24,0"
mct:StateContainer.CurrentState="{Binding CurrentState}"
mct:StateContainer.CanStateChange="{Binding CanCycleStateChange}">
<mct:StateContainer.StateViews>
<Border
mct:StateView.StateKey="Loading"
Stroke="CornflowerBlue"
Style="{StaticResource BorderStyle}">
<HorizontalStackLayout Spacing="10">
<ActivityIndicator
HeightRequest="20"
IsRunning="True"
WidthRequest="20"
Color="CornflowerBlue" />
<Label Text="Pretending to load things..." VerticalTextAlignment="Center" />
</HorizontalStackLayout>
</Border>
<Border
mct:StateView.StateKey="Success"
Stroke="Green"
Style="{StaticResource BorderStyle}">
<Label Text="Hooray! Great success!" VerticalTextAlignment="Center" />
</Border>
<Label
Padding="20"
mct:StateView.StateKey="StateKey can be anything!"
Text="Hi, I'm a simple Label state!"
TextColor="Fuchsia"
VerticalTextAlignment="Center" />
</mct:StateContainer.StateViews>
<Border Style="{StaticResource BorderStyle}">
<Label Text="This is the default content." VerticalTextAlignment="Center" />
</Border>
</VerticalStackLayout>
<Button Command="{Binding ToggleGridStateCommand}" Text="Toggle State in Grid Without Animation" />
<Label Text="A state inside a Grid spans its rows and columns." />
<Grid
mct:StateContainer.CurrentState="{Binding GridState}"
mct:StateContainer.CanStateChange="{Binding CanGridStateChange}"
ColumnDefinitions="1*, 1*, 1*"
RowDefinitions="1*, 1*"
Padding="24,0">
<mct:StateContainer.StateViews>
<Border
mct:StateView.StateKey="ReplaceGrid"
Stroke="Green"
Style="{StaticResource BorderStyle}">
<Label Text="State replacing the Grid content" VerticalTextAlignment="Center" />
</Border>
</mct:StateContainer.StateViews>
<Button
Grid.Row="0"
Grid.Column="0"
BackgroundColor="Red" />
<Button
Grid.Row="0"
Grid.Column="1"
BackgroundColor="Green" />
<Button
Grid.Row="0"
Grid.Column="2"
BackgroundColor="Blue" />
<Button
Grid.Row="1"
Grid.Column="0"
BackgroundColor="Purple" />
<Button
Grid.Row="1"
Grid.Column="1"
BackgroundColor="Yellow" />
<Button
Grid.Row="1"
Grid.Column="2"
BackgroundColor="Orange" />
</Grid>
<Button Clicked="ChangeStateWithFadeAnimation"
Text="Change State with default fade animation"
IsEnabled="{Binding CanAnimationStateChange}"/>
<Button Clicked="ChangeStateWithCustomAnimation"
Text="Change State with custom animation"
IsEnabled="{Binding CanAnimationStateChange}"/>
<Grid
x:Name="GridWithAnimation"
ColumnDefinitions="1*, 1*, 1*"
RowDefinitions="1*, 1*"
Padding="24,0"
mct:StateContainer.CanStateChange="{Binding CanAnimationStateChange}">
<mct:StateContainer.StateViews>
<Border
mct:StateView.StateKey="ReplaceGrid"
Stroke="Green"
Style="{StaticResource BorderStyle}">
<Label Text="State replacing the Grid content" VerticalTextAlignment="Center" />
</Border>
</mct:StateContainer.StateViews>
<Button
Grid.Row="0"
Grid.Column="0"
BackgroundColor="Red" />
<Button
Grid.Row="0"
Grid.Column="1"
BackgroundColor="Green" />
<Button
Grid.Row="0"
Grid.Column="2"
BackgroundColor="Blue" />
<Button
Grid.Row="1"
Grid.Column="0"
BackgroundColor="Purple" />
<Button
Grid.Row="1"
Grid.Column="1"
BackgroundColor="Yellow" />
<Button
Grid.Row="1"
Grid.Column="2"
BackgroundColor="Orange" />
</Grid>
<Button Command="{Binding ToggleNotFoundStateCommand}" Text="Toggle Nonexistent State" />
<Label TextColor="Red">
<Label.FormattedText>
<FormattedString >
<Span Text="Warning" FontAttributes="Bold"/>
<Span Text=": A StateContainerException is thrown when a StateKey is not found"/>
</FormattedString>
</Label.FormattedText>
</Label>
<VerticalStackLayout mct:StateContainer.CurrentState="{Binding NotFoundState}" >
<Border Style="{StaticResource BorderStyle}">
<Label Text="This is the default content." VerticalTextAlignment="Center" />
</Border>
</VerticalStackLayout>
</VerticalStackLayout>
</ScrollView>
</pages:BasePage>