2 using System.ComponentModel;
3 using System.Reflection;
6 namespace Tizen.NUI.Binding
8 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
9 [EditorBrowsable(EditorBrowsableState.Never)]
10 [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")]
11 [AcceptEmptyServiceProvider]
12 public sealed class XamlPropertyCondition : Condition, IValueProvider
14 readonly BindableProperty _stateProperty;
16 BindableProperty _property;
19 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
20 [EditorBrowsable(EditorBrowsableState.Never)]
21 public XamlPropertyCondition()
23 _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
26 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public BindableProperty Property
30 get { return _property; }
33 if (_property == value)
36 throw new InvalidOperationException("Can not change Property once the Trigger has been applied.");
40 if (_property != null && s_valueConverter != null)
42 Func<MemberInfo> minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName);
43 Value = s_valueConverter.Convert(Value, _property.ReturnType, minforetriever, null);
48 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
49 [EditorBrowsable(EditorBrowsableState.Never)]
52 get { return _triggerValue; }
55 if (_triggerValue == value)
58 throw new InvalidOperationException("Can not change Value once the Trigger has been applied.");
61 if (_property != null && s_valueConverter != null)
63 Func<MemberInfo> minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName);
64 _triggerValue = s_valueConverter.Convert(value, _property.ReturnType, minforetriever, null);
68 _triggerValue = value;
74 object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
76 //This is no longer required
80 internal override bool GetState(BindableObject bindable)
82 return (bool)bindable.GetValue(_stateProperty);
85 static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
87 internal override void SetUp(BindableObject bindable)
89 object newvalue = bindable.GetValue(Property);
90 bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
91 bindable.SetValue(_stateProperty, newState);
92 bindable.PropertyChanged += OnAttachedObjectPropertyChanged;
95 internal override void TearDown(BindableObject bindable)
97 bindable.ClearValue(_stateProperty);
98 bindable.PropertyChanged -= OnAttachedObjectPropertyChanged;
101 void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e)
103 var bindable = (BindableObject)sender;
104 var oldState = (bool)bindable.GetValue(_stateProperty);
106 if (Property == null)
108 if (e.PropertyName != Property.PropertyName)
110 object newvalue = bindable.GetValue(Property);
111 bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value));
112 if (oldState != newstate)
113 bindable.SetValue(_stateProperty, newstate);
116 void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
118 if ((bool)oldValue == (bool)newValue)
121 ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);