1using System.Windows.Input;
5 internal class BottomBar : ContentView, IDisposable
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;
26 Grid ContentGrid =
new Grid
30 new ColumnDefinition { Width = GridLength.Star },
31 new ColumnDefinition { Width = GridLength.Star },
32 new ColumnDefinition { Width = GridLength.Star }
39 this.border.Content = ContentGrid;
40 this.border.SetBinding(Border.StyleProperty,
new Binding(nameof(this.BorderStyle), source:
this));
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;
49 this.leftLabel =
new();
50 this.leftLabel.SetBinding(Label.TextProperty,
new Binding(nameof(this.LeftLabelText), source:
this));
52 TemplatedButton LeftButton =
new()
54 Content =
new VerticalStackLayout
63 LeftButton.SetBinding(TemplatedButton.CommandProperty,
new Binding(nameof(this.LeftCommand), source:
this));
65 ContentGrid.Add(LeftButton, 0, 0);
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;
74 this.centerLabel =
new();
75 this.centerLabel.SetBinding(Label.TextProperty,
new Binding(nameof(this.CenterLabelText), source:
this));
77 TemplatedButton CenterButton =
new()
79 Content =
new VerticalStackLayout
83 this.centerInnerBorder,
88 CenterButton.SetBinding(TemplatedButton.CommandProperty,
new Binding(nameof(this.CenterCommand), source:
this));
90 ContentGrid.Add(CenterButton, 1, 0);
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;
99 this.rightLabel =
new();
100 this.rightLabel.SetBinding(Label.TextProperty,
new Binding(nameof(this.RightLabelText), source:
this));
102 TemplatedButton RightButton =
new()
104 Content =
new VerticalStackLayout
108 this.rightInnerBorder,
113 RightButton.SetBinding(TemplatedButton.CommandProperty,
new Binding(nameof(this.RightCommand), source:
this));
115 ContentGrid.Add(RightButton, 2, 0);
117 this.VerticalOptions = LayoutOptions.End;
118 this.HorizontalOptions = LayoutOptions.Fill;
119 this.Content = this.border;
121 this.SetBinding(ActiveIconProperty,
new Binding(nameof(this.SelectedIcon), source:
this));
125 #region Bindable Properties
127 public static readonly BindableProperty LeftIconProperty =
128 BindableProperty.Create(
135 public string LeftIcon
137 get => (string)this.GetValue(LeftIconProperty);
138 set => this.SetValue(LeftIconProperty, value);
142 public static readonly BindableProperty CenterIconProperty =
143 BindableProperty.Create(
150 public string CenterIcon
152 get => (string)this.GetValue(CenterIconProperty);
153 set => this.SetValue(CenterIconProperty, value);
157 public static readonly BindableProperty RightIconProperty =
158 BindableProperty.Create(
165 public string RightIcon
167 get => (string)this.GetValue(RightIconProperty);
168 set => this.SetValue(RightIconProperty, value);
172 public static readonly BindableProperty LeftLabelTextProperty =
173 BindableProperty.Create(
174 nameof(LeftLabelText),
180 public string LeftLabelText
182 get => (string)this.GetValue(LeftLabelTextProperty);
183 set => this.SetValue(LeftLabelTextProperty, value);
187 public static readonly BindableProperty CenterLabelTextProperty =
188 BindableProperty.Create(
189 nameof(CenterLabelText),
195 public string CenterLabelText
197 get => (string)this.GetValue(CenterLabelTextProperty);
198 set => this.SetValue(CenterLabelTextProperty, value);
202 public static readonly BindableProperty RightLabelTextProperty =
203 BindableProperty.Create(
204 nameof(RightLabelText),
210 public string RightLabelText
212 get => (string)this.GetValue(RightLabelTextProperty);
213 set => this.SetValue(RightLabelTextProperty, value);
217 public static readonly BindableProperty BorderStyleProperty =
218 BindableProperty.Create(
225 public Style BorderStyle
227 get => (Style)this.GetValue(BorderStyleProperty);
228 set => this.SetValue(BorderStyleProperty, value);
232 public static readonly BindableProperty SelectedLabelStyleProperty =
233 BindableProperty.Create(
234 nameof(SelectedLabelStyle),
240 public Style SelectedLabelStyle
242 get => (Style)this.GetValue(SelectedLabelStyleProperty);
243 set => this.SetValue(SelectedLabelStyleProperty, value);
247 public static readonly BindableProperty SelectedIconStyleProperty =
248 BindableProperty.Create(
249 nameof(SelectedIconStyle),
255 public Style SelectedIconStyle
257 get => (Style)this.GetValue(SelectedIconStyleProperty);
258 set => this.SetValue(SelectedIconStyleProperty, value);
262 public static readonly BindableProperty UnselectedLabelStyleProperty =
263 BindableProperty.Create(
264 nameof(UnselectedLabelStyle),
270 public Style UnselectedLabelStyle
272 get => (Style)this.GetValue(UnselectedLabelStyleProperty);
273 set => this.SetValue(UnselectedLabelStyleProperty, value);
277 public static readonly BindableProperty UnselectedIconStyleProperty =
278 BindableProperty.Create(
279 nameof(UnselectedIconStyle),
285 public Style UnselectedIconStyle
287 get => (Style)this.GetValue(UnselectedIconStyleProperty);
288 set => this.SetValue(UnselectedIconStyleProperty, value);
292 public static readonly BindableProperty ActiveIconProperty =
293 BindableProperty.Create(
294 nameof(SelectedIcon),
297 defaultValue: ActiveIcon.Default,
298 propertyChanged: OnActiveIconChanged
301 public ActiveIcon SelectedIcon
303 get => (ActiveIcon)this.GetValue(ActiveIconProperty);
304 set => this.SetValue(ActiveIconProperty, value);
308 public static readonly BindableProperty SelectedIconBorderStyleProperty =
309 BindableProperty.Create(
310 nameof(SelectedIconBorderStyle),
316 public Style SelectedIconBorderStyle
318 get => (Style)this.GetValue(SelectedIconBorderStyleProperty);
319 set => this.SetValue(SelectedIconBorderStyleProperty, value);
323 public static readonly BindableProperty UnselectedIconBorderStyleProperty =
324 BindableProperty.Create(
325 nameof(UnselectedIconBorderStyle),
331 public Style UnselectedIconBorderStyle
333 get => (Style)this.GetValue(UnselectedIconBorderStyleProperty);
334 set => this.SetValue(UnselectedIconBorderStyleProperty, value);
338 public static readonly BindableProperty LeftCommandProperty =
339 BindableProperty.Create(
342 typeof(TemplatedButton),
346 public ICommand LeftCommand
348 get => (ICommand)this.GetValue(LeftCommandProperty);
349 set => this.SetValue(LeftCommandProperty, value);
353 public static readonly BindableProperty CenterCommandProperty =
354 BindableProperty.Create(
355 nameof(CenterCommand),
357 typeof(TemplatedButton),
361 public ICommand CenterCommand
363 get => (ICommand)this.GetValue(CenterCommandProperty);
364 set => this.SetValue(CenterCommandProperty, value);
368 public static readonly BindableProperty RightCommandProperty =
369 BindableProperty.Create(
370 nameof(RightCommand),
372 typeof(TemplatedButton),
376 public ICommand RightCommand
378 get => (ICommand)this.GetValue(RightCommandProperty);
379 set => this.SetValue(RightCommandProperty, value);
386 public static void OnActiveIconChanged(BindableObject bindable,
object oldValue,
object newValue)
388 if (bindable is BottomBar BottomBar && newValue is ActiveIcon ActiveIcon)
392 case ActiveIcon.Left:
393 BottomBar.leftIcon.Style = BottomBar.SelectedIconStyle;
394 BottomBar.centerIcon.Style = BottomBar.UnselectedIconStyle;
395 BottomBar.rightIcon.Style = BottomBar.UnselectedIconStyle;
397 BottomBar.leftInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
398 BottomBar.centerInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
399 BottomBar.rightInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
401 BottomBar.leftLabel.Style = BottomBar.SelectedLabelStyle;
402 BottomBar.centerLabel.Style = BottomBar.UnselectedLabelStyle;
403 BottomBar.rightLabel.Style = BottomBar.UnselectedLabelStyle;
405 case ActiveIcon.Center:
406 BottomBar.leftIcon.Style = BottomBar.UnselectedIconStyle;
407 BottomBar.centerIcon.Style = BottomBar.SelectedIconStyle;
408 BottomBar.rightIcon.Style = BottomBar.UnselectedIconStyle;
410 BottomBar.leftInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
411 BottomBar.centerInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
412 BottomBar.rightInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
414 BottomBar.leftLabel.Style = BottomBar.UnselectedLabelStyle;
415 BottomBar.centerLabel.Style = BottomBar.SelectedLabelStyle;
416 BottomBar.rightLabel.Style = BottomBar.UnselectedLabelStyle;
418 case ActiveIcon.Right:
419 BottomBar.leftIcon.Style = BottomBar.UnselectedIconStyle;
420 BottomBar.centerIcon.Style = BottomBar.UnselectedIconStyle;
421 BottomBar.rightIcon.Style = BottomBar.SelectedIconStyle;
423 BottomBar.leftInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
424 BottomBar.centerInnerBorder.Style = BottomBar.UnselectedIconBorderStyle;
425 BottomBar.rightInnerBorder.Style = BottomBar.SelectedIconBorderStyle;
427 BottomBar.leftLabel.Style = BottomBar.UnselectedLabelStyle;
428 BottomBar.centerLabel.Style = BottomBar.UnselectedLabelStyle;
429 BottomBar.rightLabel.Style = BottomBar.SelectedLabelStyle;
437 #region IDisposable Implementation
438 public void Dispose()
440 this.leftIcon.Dispose();
441 this.centerIcon.Dispose();
442 this.rightIcon.Dispose();
443 GC.SuppressFinalize(
this);
449 public enum ActiveIcon