2 using System.ComponentModel;
3 using System.Reflection;
4 using Tizen.NUI.Binding;
6 namespace Tizen.NUI.Xaml
8 [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
9 [AcceptEmptyServiceProvider]
10 internal sealed class PropertyCondition : Condition, IValueProvider
12 readonly BindableProperty _stateProperty;
14 BindableProperty _property;
17 public PropertyCondition()
19 _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), false, propertyChanged: OnStatePropertyChanged);
22 public BindableProperty Property
24 get { return _property; }
27 if (_property == value)
30 throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
34 if (_property != null && s_valueConverter != null)
36 Func<MemberInfo> minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName);
37 Value = s_valueConverter.Convert(Value, Property.ReturnType, minforetriever, null);
44 get { return _triggerValue; }
47 if (_triggerValue == value)
50 throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
53 if (_property != null && s_valueConverter != null)
55 Func<MemberInfo> minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName);
56 value = s_valueConverter.Convert(value, Property.ReturnType, minforetriever, null);
58 _triggerValue = value;
62 object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
64 //This is no longer required
68 internal override bool GetState(BindableObject bindable)
70 return (bool)bindable.GetValue(_stateProperty);
73 static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
75 internal override void SetUp(BindableObject bindable)
77 object newvalue = bindable.GetValue(Property);
78 bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
79 bindable.SetValue(_stateProperty, newState);
80 bindable.PropertyChanged += OnAttachedObjectPropertyChanged;
83 internal override void TearDown(BindableObject bindable)
85 bindable.ClearValue(_stateProperty);
86 bindable.PropertyChanged -= OnAttachedObjectPropertyChanged;
89 void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e)
91 var bindable = (BindableObject)sender;
92 var oldState = (bool)bindable.GetValue(_stateProperty);
96 if (e.PropertyName != Property.PropertyName)
98 object newvalue = bindable.GetValue(Property);
99 bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
100 if (oldState != newstate)
101 bindable.SetValue(_stateProperty, newstate);
104 void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
106 if ((bool)oldValue == (bool)newValue)
109 ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);