Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConditionView.cs
1using System;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
8{
9 internal class ConditionView : ContentView
10 {
11 public static readonly BindableProperty FalseProperty =
12 BindableProperty.Create(nameof(False), typeof(View), typeof(ConditionView), null, propertyChanged: OnViewChanged);
13
14 public static readonly BindableProperty TrueProperty =
15 BindableProperty.Create(nameof(True), typeof(View), typeof(ConditionView), null, propertyChanged: OnViewChanged);
16
17 public static readonly BindableProperty ConditionProperty =
18 BindableProperty.Create(nameof(Condition), typeof(bool), typeof(ConditionView), false, propertyChanged: OnConditionChanged);
19
20 private static void OnConditionChanged(BindableObject bindable, object oldValue, object newValue)
21 {
22 ((ConditionView)bindable).UpdateContent();
23 }
24
25 private static void OnViewChanged(BindableObject bindable, object oldValue, object newValue)
26 {
27 ConditionView Control = (ConditionView)bindable;
28
29 if (newValue is View View)
30 {
31 SetInheritedBindingContext(View, Control.BindingContext);
32 }
33
34 Control.UpdateContent();
35 }
36
37
38 private void UpdateContent()
39 {
40 this.Content = this.Condition ? this.True : this.False;
41 this.InvalidateMeasure();
42 }
43
44 protected override void OnBindingContextChanged()
45 {
46 {
47 base.OnBindingContextChanged();
48
49 if (this.True is not null)
50 SetInheritedBindingContext(this.True, this.BindingContext);
51
52 if (this.False is not null)
53 SetInheritedBindingContext(this.False, this.BindingContext);
54 }
55 }
56
57 public bool Condition
58 {
59 get => (bool)this.GetValue(ConditionProperty);
60 set => this.SetValue(ConditionProperty, value);
61 }
62
63 public View True
64 {
65 get => (View)this.GetValue(TrueProperty);
66 set => this.SetValue(TrueProperty, value);
67 }
68
69 public View False
70 {
71 get => (View)this.GetValue(FalseProperty);
72 set => this.SetValue(FalseProperty, value);
73 }
74 }
75
76}