-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBaseShellItem.cs
More file actions
673 lines (554 loc) · 22.4 KB
/
Copy pathBaseShellItem.cs
File metadata and controls
673 lines (554 loc) · 22.4 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#nullable disable
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.StyleSheets;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls
{
/// <summary>
/// Base class for Shell navigation items providing common properties like Title, Icon, and Route.
/// </summary>
[DebuggerDisplay("Title = {Title}, Route = {Route}")]
[DebuggerTypeProxy(typeof(BaseShellItemDebugView))]
public class BaseShellItem : NavigableElement, IPropertyPropagationController, IVisualController, IFlowDirectionController, IWindowController
{
public event EventHandler Appearing;
public event EventHandler Disappearing;
bool _hasAppearing;
const string DefaultFlyoutItemLabelStyle = "Default_FlyoutItemLabelStyle";
const string DefaultFlyoutItemImageStyle = "Default_FlyoutItemImageStyle";
const string DefaultFlyoutItemLayoutStyle = "Default_FlyoutItemLayoutStyle";
protected private ObservableCollection<Element> DeclaredChildren { get; } = new ObservableCollection<Element>();
#region PropertyKeys
internal static readonly BindablePropertyKey IsCheckedPropertyKey = BindableProperty.CreateReadOnly(nameof(IsChecked), typeof(bool), typeof(BaseShellItem), false);
#endregion PropertyKeys
/// <summary>Bindable property for <see cref="FlyoutIcon"/>.</summary>
public static readonly BindableProperty FlyoutIconProperty =
BindableProperty.Create(nameof(FlyoutIcon), typeof(ImageSource), typeof(BaseShellItem), null, BindingMode.OneTime);
/// <summary>Bindable property for <see cref="Icon"/>.</summary>
public static readonly BindableProperty IconProperty =
BindableProperty.Create(nameof(Icon), typeof(ImageSource), typeof(BaseShellItem), null, BindingMode.OneWay,
propertyChanged: OnIconChanged);
/// <summary>Bindable property for <see cref="IsChecked"/>.</summary>
public static readonly BindableProperty IsCheckedProperty = IsCheckedPropertyKey.BindableProperty;
/// <summary>Bindable property for <see cref="IsEnabled"/>.</summary>
public static readonly BindableProperty IsEnabledProperty =
BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox, BindingMode.OneWay);
/// <summary>Bindable property for <see cref="Title"/>.</summary>
public static readonly BindableProperty TitleProperty =
BindableProperty.Create(nameof(Title), typeof(string), typeof(BaseShellItem), null, BindingMode.OneWay, propertyChanged: OnTitlePropertyChanged);
/// <summary>Bindable property for <see cref="IsVisible"/>.</summary>
public static readonly BindableProperty IsVisibleProperty =
BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox);
/// <summary>Bindable property for <see cref="FlyoutItemIsVisible"/>.</summary>
public static readonly BindableProperty FlyoutItemIsVisibleProperty =
BindableProperty.Create(nameof(FlyoutItemIsVisible), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox, propertyChanged: OnFlyoutItemIsVisibleChanged);
/// <summary>Bindable property for <see cref="BadgeText"/>.</summary>
public static readonly BindableProperty BadgeTextProperty =
BindableProperty.Create(nameof(BadgeText), typeof(string), typeof(BaseShellItem), null, BindingMode.OneWay);
/// <summary>Bindable property for <see cref="BadgeColor"/>.</summary>
public static readonly BindableProperty BadgeColorProperty =
BindableProperty.Create(nameof(BadgeColor), typeof(Color), typeof(BaseShellItem), null, BindingMode.OneWay);
/// <summary>Bindable property for <see cref="BadgeTextColor"/>.</summary>
public static readonly BindableProperty BadgeTextColorProperty =
BindableProperty.Create(nameof(BadgeTextColor), typeof(Color), typeof(BaseShellItem), null, BindingMode.OneWay);
public BaseShellItem()
{
DeclaredChildren.CollectionChanged += (_, args) =>
{
if (args.NewItems != null)
foreach (Element element in args.NewItems)
AddLogicalChild(element);
if (args.OldItems != null)
foreach (Element element in args.OldItems)
RemoveLogicalChild(element);
};
}
/// <summary>
/// Gets or sets the icon displayed for this item in the flyout. This is a bindable property.
/// </summary>
public ImageSource FlyoutIcon
{
get { return (ImageSource)GetValue(FlyoutIconProperty); }
set { SetValue(FlyoutIconProperty, value); }
}
/// <summary>
/// Gets or sets the icon displayed for this item in the tab bar. This is a bindable property.
/// </summary>
public ImageSource Icon
{
get { return (ImageSource)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
/// <summary>
/// Gets a value indicating whether this item is currently selected. This is a bindable property.
/// </summary>
public bool IsChecked => (bool)GetValue(IsCheckedProperty);
/// <summary>
/// Gets or sets a value indicating whether this item is enabled. This is a bindable property.
/// </summary>
public bool IsEnabled
{
get { return (bool)GetValue(IsEnabledProperty); }
set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); }
}
/// <summary>
/// Gets or sets the route used for URI-based Shell navigation.
/// </summary>
public string Route
{
get { return Routing.GetRoute(this); }
set
{
Routing.ValidateForDuplicates(this, value);
Routing.SetRoute(this, value);
}
}
/// <summary>
/// Gets or sets the title displayed in the UI for this item. This is a bindable property.
/// </summary>
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
/// <summary>
/// Gets or sets a value indicating whether this item is visible in the Shell UI. This is a bindable property.
/// </summary>
public bool IsVisible
{
get => (bool)GetValue(IsVisibleProperty);
set => SetValue(IsVisibleProperty, BooleanBoxes.Box(value));
}
/// <summary>
/// Gets or sets a value indicating whether this item is visible in the flyout menu. This is a bindable property.
/// </summary>
public bool FlyoutItemIsVisible
{
get => (bool)GetValue(FlyoutItemIsVisibleProperty);
set => SetValue(FlyoutItemIsVisibleProperty, BooleanBoxes.Box(value));
}
/// <summary>
/// Gets or sets the badge text displayed on this Shell navigation item. This is a bindable property.
/// </summary>
/// <remarks>
/// Setting this property to a non-null, non-empty value will display a badge on the tab item.
/// Set to an empty string to show a dot indicator (small badge with no text).
/// Set to <see langword="null"/> to hide the badge.
/// On Windows, only numeric values are displayed as numbers; non-numeric text (e.g., "New") shows as a dot indicator.
/// </remarks>
public string BadgeText
{
get => (string)GetValue(BadgeTextProperty);
set => SetValue(BadgeTextProperty, value);
}
/// <summary>
/// Gets or sets the background color of the badge displayed on this Shell navigation item. This is a bindable property.
/// </summary>
public Color BadgeColor
{
get => (Color)GetValue(BadgeColorProperty);
set => SetValue(BadgeColorProperty, value);
}
/// <summary>
/// Gets or sets the foreground (text) color of the badge displayed on this Shell navigation item.
/// When set to <see langword="null"/>, the platform default text color is used (typically white).
/// This is a bindable property.
/// </summary>
/// <remarks>
/// <para>
/// Platform support:
/// </para>
/// <list type="bullet">
/// <item><description><b>Android</b>: Maps to <c>BadgeDrawable.BadgeTextColor</c>.</description></item>
/// <item><description><b>iOS/MacCatalyst</b>: Maps to <c>UITabBarItem.SetBadgeTextAttributes</c>.</description></item>
/// <item><description><b>Windows</b>: Maps to <c>InfoBadge.Foreground</c>.</description></item>
/// </list>
/// </remarks>
public Color BadgeTextColor
{
get => (Color)GetValue(BadgeTextColorProperty);
set => SetValue(BadgeTextColorProperty, value);
}
internal bool IsPartOfVisibleTree()
{
if (Parent is IShellController shell)
return shell.GetItems().Contains(this);
else if (Parent is ShellGroupItem sgi)
return sgi.ShellElementCollection.Contains(this);
return false;
}
internal virtual void SendAppearing()
{
if (_hasAppearing)
return;
_hasAppearing = true;
OnAppearing();
Appearing?.Invoke(this, EventArgs.Empty);
}
internal virtual void SendDisappearing()
{
if (!_hasAppearing)
return;
_hasAppearing = false;
OnDisappearing();
Disappearing?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnAppearing()
{
}
protected virtual void OnDisappearing()
{
}
internal void OnAppearing(Action action)
{
if (_hasAppearing)
action();
else
{
if (Navigation.ModalStack.Count > 0)
{
Navigation.ModalStack[Navigation.ModalStack.Count - 1]
.OnAppearing(action);
return;
}
else if (Navigation.NavigationStack.Count > 1)
{
Navigation.NavigationStack[Navigation.NavigationStack.Count - 1]
.OnAppearing(action);
return;
}
EventHandler eventHandler = null;
eventHandler = (_, __) =>
{
this.Appearing -= eventHandler;
action();
};
this.Appearing += eventHandler;
}
}
IVisual _effectiveVisual = Microsoft.Maui.Controls.VisualMarker.Default;
IVisual IVisualController.EffectiveVisual
{
get { return _effectiveVisual; }
set
{
if (value == _effectiveVisual)
return;
_effectiveVisual = value;
OnPropertyChanged(VisualElement.VisualProperty.PropertyName);
}
}
IVisual IVisualController.Visual => Microsoft.Maui.Controls.VisualMarker.MatchParent;
static void OnTitlePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var shellItem = (BaseShellItem)bindable;
if (shellItem.FindParentOfType<Shell>()?.Toolbar is ShellToolbar st)
st.UpdateTitle();
}
static void OnIconChanged(BindableObject bindable, object oldValue, object newValue)
{
if (newValue == null || bindable.IsSet(FlyoutIconProperty))
return;
var shellItem = (BaseShellItem)bindable;
shellItem.FlyoutIcon = (ImageSource)newValue;
}
static void OnFlyoutItemIsVisibleChanged(BindableObject bindable, object oldValue, object newValue)
{
Shell.SetFlyoutItemIsVisible(bindable, (bool)newValue);
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (Parent != null)
{
if (propertyName == Shell.ItemTemplateProperty.PropertyName || propertyName == nameof(Parent))
Propagate(Shell.ItemTemplateProperty, this, Parent, true);
}
}
internal static void PropagateFromParent(BindableProperty property, Element me)
{
if (me == null || me.Parent == null)
return;
Propagate(property, me.Parent, me, false);
}
internal static void Propagate(BindableProperty property, BindableObject from, BindableObject to, bool onlyToImplicit)
{
if (from == null || to == null)
return;
if (onlyToImplicit && Routing.IsImplicit(from))
return;
if (to is Shell)
return;
if (from.IsSet(property) && !to.IsSet(property))
to.SetValue(property, from.GetValue(property));
}
void IPropertyPropagationController.PropagatePropertyChanged(string propertyName)
{
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, ((IVisualTreeElement)this).GetVisualChildren());
}
EffectiveFlowDirection _effectiveFlowDirection = default(EffectiveFlowDirection);
EffectiveFlowDirection IFlowDirectionController.EffectiveFlowDirection
{
get { return _effectiveFlowDirection; }
set
{
if (value == _effectiveFlowDirection)
return;
_effectiveFlowDirection = value;
var ve = (Parent as VisualElement);
ve?.InvalidateMeasureInternal(InvalidationTrigger.Undefined);
OnPropertyChanged(VisualElement.FlowDirectionProperty.PropertyName);
}
}
bool IFlowDirectionController.ApplyEffectiveFlowDirectionToChildContainer => true;
double IFlowDirectionController.Width => (Parent as VisualElement)?.Width ?? 0;
static readonly BindablePropertyKey WindowPropertyKey = BindableProperty.CreateReadOnly(
nameof(Window), typeof(Window), typeof(BaseShellItem), null);
/// <summary>Bindable property for <see cref="Window"/>.</summary>
public static readonly BindableProperty WindowProperty = WindowPropertyKey.BindableProperty;
public Window Window => (Window)GetValue(WindowProperty);
Window IWindowController.Window
{
get => (Window)GetValue(WindowProperty);
set => SetValue(WindowPropertyKey, value);
}
internal virtual void ApplyQueryAttributes(ShellRouteParameters query)
{
}
static void UpdateFlyoutItemStyles(Grid flyoutItemCell, IStyleSelectable source)
{
List<string> bindableObjectStyle = new List<string>() {
DefaultFlyoutItemLabelStyle,
DefaultFlyoutItemImageStyle,
DefaultFlyoutItemLayoutStyle,
FlyoutItem.LabelStyle,
FlyoutItem.ImageStyle,
FlyoutItem.LayoutStyle };
if (source?.Classes != null)
foreach (var styleClass in source.Classes)
bindableObjectStyle.Add(styleClass);
flyoutItemCell
.StyleClass = bindableObjectStyle;
flyoutItemCell.Children.OfType<Label>().First()
.StyleClass = bindableObjectStyle;
flyoutItemCell.Children.OfType<Image>().First()
.StyleClass = bindableObjectStyle;
}
BindableObject NonImplicitParent
{
get
{
if (Parent is Shell)
return Parent;
var parent = (BaseShellItem)Parent;
if (!Routing.IsImplicit(parent))
return parent;
return parent.NonImplicitParent;
}
}
internal static DataTemplate CreateDefaultFlyoutItemCell(BindableObject bo)
{
return new DataTemplate(() =>
{
var grid = new Grid()
{
#pragma warning disable CS0618 // Type or member is obsolete
IgnoreSafeArea = true
#pragma warning restore CS0618 // Type or member is obsolete
};
if (OperatingSystem.IsWindows())
grid.ColumnSpacing = grid.RowSpacing = 0;
grid.Resources = new ResourceDictionary();
var defaultLabelClass = new Style(typeof(Label))
{
Setters = {
new Setter { Property = Label.VerticalTextAlignmentProperty, Value = TextAlignment.Center }
},
Class = DefaultFlyoutItemLabelStyle,
};
var defaultImageClass = new Style(typeof(Image))
{
Setters = {
new Setter { Property = Image.VerticalOptionsProperty, Value = LayoutOptions.Center }
},
Class = DefaultFlyoutItemImageStyle,
};
var defaultGridClass = new Style(typeof(Grid))
{
Class = DefaultFlyoutItemLayoutStyle,
};
var groups = new VisualStateGroupList();
var commonGroup = new VisualStateGroup();
commonGroup.Name = "CommonStates";
groups.Add(commonGroup);
var normalState = new VisualState();
normalState.Name = "Normal";
commonGroup.States.Add(normalState);
var selectedState = new VisualState();
selectedState.Name = "Selected";
if (!OperatingSystem.IsWindows())
{
selectedState.Setters.Add(new Setter
{
Property = VisualElement.BackgroundColorProperty,
Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) }
});
}
normalState.Setters.Add(new Setter
{
Property = VisualElement.BackgroundColorProperty,
Value = Colors.Transparent
});
commonGroup.States.Add(selectedState);
defaultGridClass.Setters.Add(new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = groups });
if (OperatingSystem.IsAndroid())
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 50 });
else
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 44 });
ColumnDefinitionCollection columnDefinitions = new ColumnDefinitionCollection();
if (OperatingSystem.IsAndroid())
columnDefinitions.Add(new ColumnDefinition { Width = 54 });
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
columnDefinitions.Add(new ColumnDefinition { Width = 50 });
else if (OperatingSystem.IsWindows())
columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
else if (DeviceInfo.Platform == DevicePlatform.Tizen)
columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
defaultGridClass.Setters.Add(new Setter { Property = Grid.ColumnDefinitionsProperty, Value = columnDefinitions });
BindingBase automationIdBinding = Binding.Create(static (Element element) => element.AutomationId);
defaultGridClass.Setters.Add(new Setter { Property = Element.AutomationIdProperty, Value = automationIdBinding });
BindingBase imageBinding = null;
BindingBase labelBinding = null;
if (bo is MenuItem)
{
imageBinding = Binding.Create(static (MenuItem item) => item.IconImageSource);
labelBinding = Binding.Create(static (MenuItem item) => item.Text);
}
else
{
imageBinding = Binding.Create(static (BaseShellItem item) => item.FlyoutIcon);
labelBinding = Binding.Create(static (BaseShellItem item) => item.Title);
}
var image = new Image();
double sizeRequest = -1;
if (OperatingSystem.IsAndroid())
sizeRequest = 24;
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
sizeRequest = 22;
else if (OperatingSystem.IsWindows())
sizeRequest = 16;
else if (DeviceInfo.Platform == DevicePlatform.Tizen)
sizeRequest = 25;
if (sizeRequest > 0)
{
defaultImageClass.Setters.Add(new Setter() { Property = Image.HeightRequestProperty, Value = sizeRequest });
defaultImageClass.Setters.Add(new Setter() { Property = Image.WidthRequestProperty, Value = sizeRequest });
}
if (OperatingSystem.IsWindows())
{
defaultImageClass.Setters.Add(new Setter { Property = Image.HorizontalOptionsProperty, Value = LayoutOptions.Start });
defaultImageClass.Setters.Add(new Setter { Property = Image.MarginProperty, Value = new Thickness(12, 0, 12, 0) });
}
defaultImageClass.Setters.Add(new Setter { Property = Image.SourceProperty, Value = imageBinding });
grid.Add(image);
var label = new Label();
defaultLabelClass.Setters.Add(new Setter { Property = Label.TextProperty, Value = labelBinding });
grid.Add(label, 1, 0);
if (OperatingSystem.IsAndroid())
{
object textColor;
if (Application.Current == null)
{
textColor = Colors.Black.MultiplyAlpha(0.87f);
}
else
{
textColor = new AppThemeBinding { Light = Colors.Black.MultiplyAlpha(0.87f), Dark = Colors.White };
}
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 14 });
defaultLabelClass.Setters.Add(new Setter { Property = Label.TextColorProperty, Value = textColor });
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontFamilyProperty, Value = "sans-serif-medium" });
defaultLabelClass.Setters.Add(new Setter { Property = Label.MarginProperty, Value = new Thickness(20, 0, 0, 0) });
}
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 14 });
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontAttributesProperty, Value = FontAttributes.Bold });
}
else if (OperatingSystem.IsWindows())
{
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalOptionsProperty, Value = LayoutOptions.Start });
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
}
else if (DeviceInfo.Platform == DevicePlatform.Tizen)
{
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalOptionsProperty, Value = LayoutOptions.Start });
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
}
INameScope nameScope = new NameScope();
NameScope.SetNameScope(grid, nameScope);
nameScope.RegisterName("FlyoutItemLayout", grid);
nameScope.RegisterName("FlyoutItemImage", image);
nameScope.RegisterName("FlyoutItemLabel", label);
ActionDisposable previousBindingContext = null;
grid.BindingContextChanged += (sender, _) =>
{
previousBindingContext?.Dispose();
previousBindingContext = null;
if (sender is Grid g)
{
var bo = g.BindingContext as BindableObject;
var styleClassSource = (bo is null ? null : Shell.GetBindableObjectWithFlyoutItemTemplate(bo)) as IStyleSelectable;
UpdateFlyoutItemStyles(g, styleClassSource);
// this means they haven't changed the BaseShellItemContext so we are
// going to propagate the semantic properties to the default template
if (g.BindingContext is BaseShellItem bsi)
{
previousBindingContext = SemanticProperties.FakeBindSemanticProperties(bsi, g);
// If the user hasn't set a semantic property on the flyout item then we'll
// just bind the semantic description to the title
if (!g.IsSet(SemanticProperties.DescriptionProperty))
{
g.SetBinding(SemanticProperties.DescriptionProperty, static (BaseShellItem item) => item.Title);
}
}
}
};
grid.Resources = new ResourceDictionary() { defaultGridClass, defaultLabelClass, defaultImageClass };
return grid;
});
}
/// <summary>
/// Provides a debug view for the <see cref="BaseShellItem"/> class.
/// </summary>
/// <param name="baseShellItem">The <see cref="BaseShellItem"/> instance to debug.</param>
private protected class BaseShellItemDebugView(BaseShellItem baseShellItem)
{
public ImageSource Icon => baseShellItem.Icon;
public ImageSource FlyoutIcon => baseShellItem.FlyoutIcon;
public bool FlyoutItemIsVisible => baseShellItem.FlyoutItemIsVisible;
public string Route => baseShellItem.Route;
}
#if NETSTANDARD
sealed class OperatingSystem
{
public static bool IsAndroid() => false;
public static bool IsIOS() => false;
public static bool IsMacCatalyst() => false;
public static bool IsWindows() => false;
}
#endif
}
public interface IQueryAttributable
{
void ApplyQueryAttributes(IDictionary<string, object> query);
}
}