4using Microsoft.Maui.Controls;
12 internal class SwitchCaseView<T> : ContentView where T : notnull
17 public static readonly BindableProperty CasesProperty = BindableProperty.Create(
19 typeof(ICollection<CaseView<T>>),
20 typeof(SwitchCaseView<T>),
21 new List<CaseView<T>>(),
22 propertyChanged: SwitchChanged);
27 public static readonly BindableProperty DefaultProperty = BindableProperty.Create(
30 typeof(SwitchCaseView<T>),
32 propertyChanged: SwitchChanged);
37 public static readonly BindableProperty SwitchProperty = BindableProperty.Create(
40 typeof(SwitchCaseView<T>),
42 propertyChanged: SwitchChanged);
51 private static void SwitchChanged(BindableObject bindable,
object oldValue,
object newValue)
53 SwitchCaseView<T> SwitchCaseView = (SwitchCaseView<T>)bindable;
55 SwitchCaseView.Content = SwitchCaseView.Cases
56 .Where(x => x.Case.Equals(SwitchCaseView.Switch))
57 .Select(x => x.Content)
58 .SingleOrDefault() ?? SwitchCaseView.Default;
66 get => (T)this.GetValue(SwitchProperty);
67 set => this.SetValue(SwitchProperty, value);
75 get => (View)this.GetValue(DefaultProperty);
76 set => this.SetValue(DefaultProperty, value);
82 public ICollection<CaseView<T>> Cases
84 get => (ICollection<CaseView<T>>)this.GetValue(CasesProperty);
85 set => this.SetValue(CasesProperty, value);
93 internal class CaseView<T> : ContentView
98 public static readonly BindableProperty CaseProperty = BindableProperty.Create(
109 get => (T)this.GetValue(CaseProperty);
110 set => this.SetValue(CaseProperty, value);