2 using System.ComponentModel;
5 namespace Tizen.NUI.Binding
7 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
8 [EditorBrowsable(EditorBrowsableState.Never)]
9 [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")]
10 [AcceptEmptyServiceProvider]
11 public sealed class BindingCondition : Condition, IValueProvider
13 readonly BindableProperty _boundProperty;
18 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
19 [EditorBrowsable(EditorBrowsableState.Never)]
20 public BindingCondition()
22 _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged);
25 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public BindingBase Binding
29 get { return _binding; }
32 if (_binding == value)
35 throw new InvalidOperationException("Can not change Binding once the Condition has been applied.");
40 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
41 [EditorBrowsable(EditorBrowsableState.Never)]
44 get { return _triggerValue; }
47 if (_triggerValue == value)
50 throw new InvalidOperationException("Can not change Value once the Condition has been applied.");
51 _triggerValue = value;
55 object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
57 //This is no longer required
61 internal override bool GetState(BindableObject bindable)
63 object newValue = bindable.GetValue(_boundProperty);
64 return EqualsToValue(newValue);
67 internal override void SetUp(BindableObject bindable)
70 bindable.SetBinding(_boundProperty, Binding.Clone());
73 internal override void TearDown(BindableObject bindable)
75 bindable.RemoveBinding(_boundProperty);
76 bindable.ClearValue(_boundProperty);
79 static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
81 bool EqualsToValue(object other)
83 if ((other == Value) || (other != null && other.Equals(Value)))
86 object converted = null;
87 if (s_valueConverter != null)
88 converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null);
92 return (other == converted) || (other != null && other.Equals(converted));
95 void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
97 bool oldState = EqualsToValue(oldValue);
98 bool newState = EqualsToValue(newValue);
100 if (newState == oldState)
103 if (ConditionChanged != null)
104 ConditionChanged(bindable, oldState, newState);