forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionViewOptionsPage.xaml.cs
278 lines (265 loc) · 10 KB
/
CollectionViewOptionsPage.xaml.cs
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
using Maui.Controls.Sample.CollectionViewGalleries;
namespace Maui.Controls.Sample
{
public partial class CollectionViewOptionsPage : ContentPage
{
private CollectionViewViewModel _viewModel;
public CollectionViewOptionsPage(CollectionViewViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}
private void ApplyButton_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
private void OnEmptyViewChanged(object sender, CheckedChangedEventArgs e)
{
if (EmptyViewNone.IsChecked)
{
_viewModel.EmptyView = null;
}
else if (EmptyViewString.IsChecked)
{
_viewModel.EmptyView = "No Items Available(String)";
}
}
private void OnHeaderChanged(object sender, CheckedChangedEventArgs e)
{
if (HeaderNone.IsChecked)
{
_viewModel.Header = null;
}
else if (HeaderString.IsChecked)
{
_viewModel.Header = "CollectionView Header(String)";
}
else if (HeaderGrid.IsChecked)
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "CollectionView Header(Grid View)",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Blue,
AutomationId = "HeaderViewLabel"
});
_viewModel.Header = grid;
}
}
private void OnFooterChanged(object sender, CheckedChangedEventArgs e)
{
if (FooterNone.IsChecked)
{
_viewModel.Footer = null;
}
else if (FooterString.IsChecked)
{
_viewModel.Footer = "CollectionView Footer(String)";
}
else if (FooterGrid.IsChecked)
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "CollectionView Footer(Grid View)",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Red,
AutomationId = "FooterViewLabel"
});
_viewModel.Footer = grid;
}
}
private void OnHeaderTemplateChanged(object sender, CheckedChangedEventArgs e)
{
if (HeaderTemplateNone.IsChecked)
{
_viewModel.HeaderTemplate = null;
}
else if (HeaderTemplateGrid.IsChecked)
{
_viewModel.HeaderTemplate = new DataTemplate(() =>
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "Header Template(Grid View)",
FontSize = 18,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Blue,
AutomationId = "HeaderTemplateLabel"
});
return grid;
});
}
}
private void OnFooterTemplateChanged(object sender, CheckedChangedEventArgs e)
{
if (FooterTemplateNone.IsChecked)
{
_viewModel.FooterTemplate = null;
}
else if (FooterTemplateGrid.IsChecked)
{
_viewModel.FooterTemplate = new DataTemplate(() =>
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "Footer Template(Grid View)",
FontSize = 18,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Green,
AutomationId = "FooterTemplateLabel"
});
return grid;
});
}
}
private void OnGroupHeaderTemplateChanged(object sender, CheckedChangedEventArgs e)
{
if (GroupHeaderTemplateNone.IsChecked)
{
_viewModel.GroupHeaderTemplate = null;
}
else if (GroupHeaderTemplateGrid.IsChecked)
{
_viewModel.GroupHeaderTemplate = new DataTemplate(() =>
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "Group Header Template(Grid View)",
FontSize = 18,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Green,
AutomationId = "GroupHeaderTemplateLabel"
});
return grid;
});
}
}
private void OnGroupFooterTemplateChanged(object sender, CheckedChangedEventArgs e)
{
if (GroupFooterTemplateNone.IsChecked)
{
_viewModel.GroupFooterTemplate = null;
}
else if (GroupFooterTemplateGrid.IsChecked)
{
_viewModel.GroupFooterTemplate = new DataTemplate(() =>
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
Padding = new Thickness(10)
};
grid.Children.Add(new Label
{
Text = "Group Footer Template(Grid View)",
FontSize = 18,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Red,
AutomationId = "GroupFooterTemplateLabel"
});
return grid;
});
}
}
private void OnIsGroupedChanged(object sender, CheckedChangedEventArgs e)
{
if (IsGroupedFalse.IsChecked)
{
_viewModel.IsGrouped = false;
}
else if (IsGroupedTrue.IsChecked)
{
_viewModel.IsGrouped = true;
}
}
private void OnItemTemplateChanged(object sender, CheckedChangedEventArgs e)
{
if (ItemTemplateNone.IsChecked)
{
_viewModel.ItemTemplate = null;
}
else if (ItemTemplateBasic.IsChecked)
{
_viewModel.ItemTemplate = new DataTemplate(() =>
{
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Caption"));
return label;
});
}
}
private void OnItemsLayoutChanged(object sender, CheckedChangedEventArgs e)
{
if (ItemsLayoutVerticalList.IsChecked)
{
_viewModel.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
}
else if (ItemsLayoutHorizontalList.IsChecked)
{
_viewModel.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);
}
else if (ItemsLayoutVerticalGrid.IsChecked)
{
_viewModel.ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical); // 2 columns
}
else if (ItemsLayoutHorizontalGrid.IsChecked)
{
_viewModel.ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Horizontal); // 2 rows
}
}
private void OnItemsSourceChanged(object sender, CheckedChangedEventArgs e)
{
if (!(sender is RadioButton radioButton) || !e.Value)
return;
if (radioButton == ItemsSourceObservableCollection25)
_viewModel.ItemsSourceType = ItemsSourceType.ObservableCollection25T;
else if (radioButton == ItemsSourceObservableCollection5)
_viewModel.ItemsSourceType = ItemsSourceType.ObservableCollection5T;
else if (radioButton == ItemsSourceGroupedList)
_viewModel.ItemsSourceType = ItemsSourceType.GroupedListT;
else if (radioButton == ItemsSourceNone)
_viewModel.ItemsSourceType = ItemsSourceType.None;
}
}
}