1 using System.Collections.Generic;
3 namespace Tizen.NUI.Binding
5 internal sealed class MultiCondition : Condition
7 readonly BindableProperty _aggregatedStateProperty;
9 public MultiCondition()
11 _aggregatedStateProperty = BindableProperty.CreateAttached("AggregatedState", typeof(bool), typeof(MultiCondition), false, propertyChanged: OnAggregatedStatePropertyChanged);
12 Conditions = new TriggerBase.SealedList<Condition>();
15 public IList<Condition> Conditions { get; }
17 internal override bool GetState(BindableObject bindable)
19 return (bool)bindable.GetValue(_aggregatedStateProperty);
22 internal override void OnSealed()
24 ((TriggerBase.SealedList<Condition>)Conditions).IsReadOnly = true;
25 foreach (Condition condition in Conditions)
26 condition.ConditionChanged = OnConditionChanged;
29 internal override void SetUp(BindableObject bindable)
31 foreach (Condition condition in Conditions)
32 condition.SetUp(bindable);
35 internal override void TearDown(BindableObject bindable)
37 foreach (Condition condition in Conditions)
38 condition.TearDown(bindable);
41 void OnAggregatedStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
43 if ((bool)oldValue == (bool)newValue)
46 ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);
49 void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)
51 var oldState = (bool)bindable.GetValue(_aggregatedStateProperty);
53 foreach (Condition condition in Conditions)
55 if (!condition.GetState(bindable))
61 if (newState != oldState)
62 bindable.SetValue(_aggregatedStateProperty, newState);