5using System.Threading.Tasks;
9 internal class ConditionView : ContentView
11 public static readonly BindableProperty FalseProperty =
12 BindableProperty.Create(nameof(False), typeof(View), typeof(ConditionView),
null, propertyChanged: OnViewChanged);
14 public static readonly BindableProperty TrueProperty =
15 BindableProperty.Create(nameof(True), typeof(View), typeof(ConditionView),
null, propertyChanged: OnViewChanged);
17 public static readonly BindableProperty ConditionProperty =
18 BindableProperty.Create(nameof(Condition), typeof(
bool), typeof(ConditionView),
false, propertyChanged: OnConditionChanged);
20 private static void OnConditionChanged(BindableObject bindable,
object oldValue,
object newValue)
22 ((ConditionView)bindable).UpdateContent();
25 private static void OnViewChanged(BindableObject bindable,
object oldValue,
object newValue)
27 ConditionView Control = (ConditionView)bindable;
29 if (newValue is View View)
31 SetInheritedBindingContext(View, Control.BindingContext);
34 Control.UpdateContent();
38 private void UpdateContent()
40 this.Content = this.Condition ? this.True : this.False;
41 this.InvalidateMeasure();
44 protected override void OnBindingContextChanged()
47 base.OnBindingContextChanged();
49 if (this.True is not
null)
50 SetInheritedBindingContext(this.True, this.BindingContext);
52 if (this.False is not
null)
53 SetInheritedBindingContext(this.False, this.BindingContext);
59 get => (bool)this.GetValue(ConditionProperty);
60 set => this.SetValue(ConditionProperty, value);
65 get => (View)this.GetValue(TrueProperty);
66 set => this.SetValue(TrueProperty, value);
71 get => (View)this.GetValue(FalseProperty);
72 set => this.SetValue(FalseProperty, value);