Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BottomBar.cs
1using System.Windows.Input;
2
4{
5 internal class BottomBar : ContentView, IDisposable
6 {
7 #region Fields
8
9 private readonly SvgView leftIcon;
10 private readonly SvgView centerIcon;
11 private readonly SvgView rightIcon;
12 private readonly Border border;
13 private readonly Border leftInnerBorder;
14 private readonly Border centerInnerBorder;
15 private readonly Border rightInnerBorder;
16 private readonly Label leftLabel;
17 private readonly Label centerLabel;
18 private readonly Label rightLabel;
19
20 #endregion
21
22 #region Constructor
23 public BottomBar()
24 {
25 // LeftIcon, CenterIcon, RightIcon
26 Grid ContentGrid = new Grid
27 {
28 ColumnDefinitions =
29 {
30 new ColumnDefinition { Width = GridLength.Star }, // LeftIcon
31 new ColumnDefinition { Width = GridLength.Star }, // CenterIcon
32 new ColumnDefinition { Width = GridLength.Star } // RightIcon
33 },
34 Margin = 0
35 };
36
37 // Main Border
38 this.border = new();
39 this.border.Content = ContentGrid;
40 this.border.SetBinding(Border.StyleProperty, new Binding(nameof(this.BorderStyle), source: this));
41
42 // LeftIcon
43 this.leftIcon = new SvgView();
44 this.leftIcon.VerticalOptions = LayoutOptions.Center;
45 this.leftIcon.SetBinding(SvgView.SourceProperty, new Binding(nameof(this.LeftIcon), source: this));
46 this.leftInnerBorder = new();
47 this.leftInnerBorder.Content = this.leftIcon;
48
49 this.leftLabel = new();
50 this.leftLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.LeftLabelText), source: this));
51
52 TemplatedButton LeftButton = new()
53 {
54 Content = new VerticalStackLayout
55 {
56 Children =
57 {
58 this.leftInnerBorder,
59 this.leftLabel
60 }
61 }
62 };
63 LeftButton.SetBinding(TemplatedButton.CommandProperty, new Binding(nameof(this.LeftCommand), source: this));
64
65 ContentGrid.Add(LeftButton, 0, 0);
66
67 // CenterIcon
68 this.centerIcon = new SvgView();
69 this.centerIcon.VerticalOptions = LayoutOptions.Center;
70 this.centerIcon.SetBinding(SvgView.SourceProperty, new Binding(nameof(this.CenterIcon), source: this));
71 this.centerInnerBorder = new();
72 this.centerInnerBorder.Content = this.centerIcon;
73
74 this.centerLabel = new();
75 this.centerLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.CenterLabelText), source: this));
76
77 TemplatedButton CenterButton = new()
78 {
79 Content = new VerticalStackLayout
80 {
81 Children =
82 {
83 this.centerInnerBorder,
84 this.centerLabel
85 }
86 }
87 };
88 CenterButton.SetBinding(TemplatedButton.CommandProperty, new Binding(nameof(this.CenterCommand), source: this));
89
90 ContentGrid.Add(CenterButton, 1, 0);
91
92 // RightIcon
93 this.rightIcon = new SvgView();
94 this.rightIcon.VerticalOptions = LayoutOptions.Center;
95 this.rightIcon.SetBinding(SvgView.SourceProperty, new Binding(nameof(this.RightIcon), source: this));
96 this.rightInnerBorder = new();
97 this.rightInnerBorder.Content = this.rightIcon;
98
99 this.rightLabel = new();
100 this.rightLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.RightLabelText), source: this));
101
102 TemplatedButton RightButton = new()
103 {
104 Content = new VerticalStackLayout
105 {
106 Children =
107 {
108 this.rightInnerBorder,
109 this.rightLabel
110 }
111 }
112 };
113 RightButton.SetBinding(TemplatedButton.CommandProperty, new Binding(nameof(this.RightCommand), source: this));
114
115 ContentGrid.Add(RightButton, 2, 0);
116
117 this.VerticalOptions = LayoutOptions.End;
118 this.HorizontalOptions = LayoutOptions.Fill;
119 this.Content = this.border;
120
121 this.SetBinding(ActiveIconProperty, new Binding(nameof(this.SelectedIcon), source: this));
122 }
123 #endregion
124
125 #region Bindable Properties
126 // LeftIcon Property
127 public static readonly BindableProperty LeftIconProperty =
128 BindableProperty.Create(
129 nameof(LeftIcon),
130 typeof(string),
131 typeof(SvgView),
132 null
133 );
134
135 public string LeftIcon
136 {
137 get => (string)this.GetValue(LeftIconProperty);
138 set => this.SetValue(LeftIconProperty, value);
139 }
140
141 // CenterIcon Property
142 public static readonly BindableProperty CenterIconProperty =
143 BindableProperty.Create(
144 nameof(CenterIcon),
145 typeof(string),
146 typeof(SvgView),
147 null
148 );
149
150 public string CenterIcon
151 {
152 get => (string)this.GetValue(CenterIconProperty);
153 set => this.SetValue(CenterIconProperty, value);
154 }
155
156 // RightIcon Property
157 public static readonly BindableProperty RightIconProperty =
158 BindableProperty.Create(
159 nameof(RightIcon),
160 typeof(string),
161 typeof(SvgView),
162 null
163 );
164
165 public string RightIcon
166 {
167 get => (string)this.GetValue(RightIconProperty);
168 set => this.SetValue(RightIconProperty, value);
169 }
170
171 // Left label Text Property
172 public static readonly BindableProperty LeftLabelTextProperty =
173 BindableProperty.Create(
174 nameof(LeftLabelText),
175 typeof(string),
176 typeof(Label),
177 null
178 );
179
180 public string LeftLabelText
181 {
182 get => (string)this.GetValue(LeftLabelTextProperty);
183 set => this.SetValue(LeftLabelTextProperty, value);
184 }
185
186 // Center label Text Property
187 public static readonly BindableProperty CenterLabelTextProperty =
188 BindableProperty.Create(
189 nameof(CenterLabelText),
190 typeof(string),
191 typeof(Label),
192 null
193 );
194
195 public string CenterLabelText
196 {
197 get => (string)this.GetValue(CenterLabelTextProperty);
198 set => this.SetValue(CenterLabelTextProperty, value);
199 }
200
201 // Right label Text Property
202 public static readonly BindableProperty RightLabelTextProperty =
203 BindableProperty.Create(
204 nameof(RightLabelText),
205 typeof(string),
206 typeof(Label),
207 null
208 );
209
210 public string RightLabelText
211 {
212 get => (string)this.GetValue(RightLabelTextProperty);
213 set => this.SetValue(RightLabelTextProperty, value);
214 }
215
216 // Border Style Property
217 public static readonly BindableProperty BorderStyleProperty =
218 BindableProperty.Create(
219 nameof(BorderStyle),
220 typeof(Style),
221 typeof(Border),
222 null
223 );
224
225 public Style BorderStyle
226 {
227 get => (Style)this.GetValue(BorderStyleProperty);
228 set => this.SetValue(BorderStyleProperty, value);
229 }
230
231 // Selected Label Style
232 public static readonly BindableProperty SelectedLabelStyleProperty =
233 BindableProperty.Create(
234 nameof(SelectedLabelStyle),
235 typeof(Style),
236 typeof(Label),
237 null
238 );
239
240 public Style SelectedLabelStyle
241 {
242 get => (Style)this.GetValue(SelectedLabelStyleProperty);
243 set => this.SetValue(SelectedLabelStyleProperty, value);
244 }
245
246 // Selected Icon Style
247 public static readonly BindableProperty SelectedIconStyleProperty =
248 BindableProperty.Create(
249 nameof(SelectedIconStyle),
250 typeof(Style),
251 typeof(SvgView),
252 null
253 );
254
255 public Style SelectedIconStyle
256 {
257 get => (Style)this.GetValue(SelectedIconStyleProperty);
258 set => this.SetValue(SelectedIconStyleProperty, value);
259 }
260
261 // Unselected Label Style
262 public static readonly BindableProperty UnselectedLabelStyleProperty =
263 BindableProperty.Create(
264 nameof(UnselectedLabelStyle),
265 typeof(Style),
266 typeof(Label),
267 null
268 );
269
270 public Style UnselectedLabelStyle
271 {
272 get => (Style)this.GetValue(UnselectedLabelStyleProperty);
273 set => this.SetValue(UnselectedLabelStyleProperty, value);
274 }
275
276 // Unselected Icon Style
277 public static readonly BindableProperty UnselectedIconStyleProperty =
278 BindableProperty.Create(
279 nameof(UnselectedIconStyle),
280 typeof(Style),
281 typeof(SvgView),
282 null
283 );
284
285 public Style UnselectedIconStyle
286 {
287 get => (Style)this.GetValue(UnselectedIconStyleProperty);
288 set => this.SetValue(UnselectedIconStyleProperty, value);
289 }
290
291 // ActiveIcon Property
292 public static readonly BindableProperty ActiveIconProperty =
293 BindableProperty.Create(
294 nameof(SelectedIcon),
295 typeof(ActiveIcon),
296 typeof(BottomBar),
297 defaultValue: ActiveIcon.Default,
298 propertyChanged: OnActiveIconChanged
299 );
300
301 public ActiveIcon SelectedIcon
302 {
303 get => (ActiveIcon)this.GetValue(ActiveIconProperty);
304 set => this.SetValue(ActiveIconProperty, value);
305 }
306
307 // Selected Icon Border Style Property
308 public static readonly BindableProperty SelectedIconBorderStyleProperty =
309 BindableProperty.Create(
310 nameof(SelectedIconBorderStyle),
311 typeof(Style),
312 typeof(Border),
313 null
314 );
315
316 public Style SelectedIconBorderStyle
317 {
318 get => (Style)this.GetValue(SelectedIconBorderStyleProperty);
319 set => this.SetValue(SelectedIconBorderStyleProperty, value);
320 }
321
322 // Unselected Icon Border Style Property
323 public static readonly BindableProperty UnselectedIconBorderStyleProperty =
324 BindableProperty.Create(
325 nameof(UnselectedIconBorderStyle),
326 typeof(Style),
327 typeof(Border),
328 null
329 );
330
331 public Style UnselectedIconBorderStyle
332 {
333 get => (Style)this.GetValue(UnselectedIconBorderStyleProperty);
334 set => this.SetValue(UnselectedIconBorderStyleProperty, value);
335 }
336
337 // Left Button Command Property
338 public static readonly BindableProperty LeftCommandProperty =
339 BindableProperty.Create(
340 nameof(LeftCommand),
341 typeof(ICommand),
342 typeof(TemplatedButton),
343 null
344 );
345
346 public ICommand LeftCommand
347 {
348 get => (ICommand)this.GetValue(LeftCommandProperty);
349 set => this.SetValue(LeftCommandProperty, value);
350 }
351
352 // Center Button Command Property
353 public static readonly BindableProperty CenterCommandProperty =
354 BindableProperty.Create(
355 nameof(CenterCommand),
356 typeof(ICommand),
357 typeof(TemplatedButton),
358 null
359 );
360
361 public ICommand CenterCommand
362 {
363 get => (ICommand)this.GetValue(CenterCommandProperty);
364 set => this.SetValue(CenterCommandProperty, value);
365 }
366
367 // Right Button Command Property
368 public static readonly BindableProperty RightCommandProperty =
369 BindableProperty.Create(
370 nameof(RightCommand),
371 typeof(ICommand),
372 typeof(TemplatedButton),
373 null
374 );
375
376 public ICommand RightCommand
377 {
378 get => (ICommand)this.GetValue(RightCommandProperty);
379 set => this.SetValue(RightCommandProperty, value);
380 }
381
382 #endregion
383
384 #region OnChanged
385
386 public static void OnActiveIconChanged(BindableObject bindable, object oldValue, object newValue)
387 {
388 if (bindable is BottomBar BottomBar && newValue is ActiveIcon ActiveIcon)
389 {
390 switch (ActiveIcon)
391 {
392 case ActiveIcon.Left:
393 BottomBar.leftIcon.Style = BottomBar.SelectedIconStyle;
394 BottomBar.centerIcon.Style = BottomBar.UnselectedIconStyle;
395 BottomBar.rightIcon.Style = BottomBar.UnselectedIconStyle;
396
397 BottomBar.leftInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
398 BottomBar.centerInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
399 BottomBar.rightInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
400
401 BottomBar.leftLabel.Style = BottomBar.SelectedLabelStyle;
402 BottomBar.centerLabel.Style = BottomBar.UnselectedLabelStyle;
403 BottomBar.rightLabel.Style = BottomBar.UnselectedLabelStyle;
404 break;
405 case ActiveIcon.Center:
406 BottomBar.leftIcon.Style = BottomBar.UnselectedIconStyle;
407 BottomBar.centerIcon.Style = BottomBar.SelectedIconStyle;
408 BottomBar.rightIcon.Style = BottomBar.UnselectedIconStyle;
409
410 BottomBar.leftInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
411 BottomBar.centerInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
412 BottomBar.rightInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
413
414 BottomBar.leftLabel.Style = BottomBar.UnselectedLabelStyle;
415 BottomBar.centerLabel.Style = BottomBar.SelectedLabelStyle;
416 BottomBar.rightLabel.Style = BottomBar.UnselectedLabelStyle;
417 break;
418 case ActiveIcon.Right:
419 BottomBar.leftIcon.Style = BottomBar.UnselectedIconStyle;
420 BottomBar.centerIcon.Style = BottomBar.UnselectedIconStyle;
421 BottomBar.rightIcon.Style = BottomBar.SelectedIconStyle;
422
423 BottomBar.leftInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
424 BottomBar.centerInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
425 BottomBar.rightInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
426
427 BottomBar.leftLabel.Style = BottomBar.UnselectedLabelStyle;
428 BottomBar.centerLabel.Style = BottomBar.UnselectedLabelStyle;
429 BottomBar.rightLabel.Style = BottomBar.SelectedLabelStyle;
430 break;
431 }
432 }
433 }
434
435 #endregion
436
437 #region IDisposable Implementation
438 public void Dispose()
439 {
440 this.leftIcon.Dispose();
441 this.centerIcon.Dispose();
442 this.rightIcon.Dispose();
443 GC.SuppressFinalize(this);
444 }
445 #endregion
446
447 #region Enum
448
449 public enum ActiveIcon
450 {
451 Left,
452 Center,
453 Right,
454 Default // DO NOT USE, THIS ONLY MAKES IT SO ON SELECTED ICON CHANGED WORKS
455 }
456
457 #endregion
458 }
459}