4 namespace Tizen.NUI.XamlBinding
6 [ProvideCompiled("Tizen.NUI.Xaml.Forms.XamlC.PassthroughValueProvider")]
7 [AcceptEmptyServiceProvider]
8 internal sealed class BindingCondition : Condition, IValueProvider
10 readonly BindableProperty _boundProperty;
15 public BindingCondition()
17 _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged);
20 public BindingBase Binding
22 get { return _binding; }
25 if (_binding == value)
28 throw new InvalidOperationException("Can not change Binding once the Condition has been applied.");
35 get { return _triggerValue; }
38 if (_triggerValue == value)
41 throw new InvalidOperationException("Can not change Value once the Condition has been applied.");
42 _triggerValue = value;
46 object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
48 //This is no longer required
52 internal override bool GetState(BindableObject bindable)
54 object newValue = bindable.GetValue(_boundProperty);
55 return EqualsToValue(newValue);
58 internal override void SetUp(BindableObject bindable)
61 bindable.SetBinding(_boundProperty, Binding.Clone());
64 internal override void TearDown(BindableObject bindable)
66 bindable.RemoveBinding(_boundProperty);
67 bindable.ClearValue(_boundProperty);
70 static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
72 bool EqualsToValue(object other)
74 if ((other == Value) || (other != null && other.Equals(Value)))
77 object converted = null;
78 if (s_valueConverter != null)
79 converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null);
83 return (other == converted) || (other != null && other.Equals(converted));
86 void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
88 bool oldState = EqualsToValue(oldValue);
89 bool newState = EqualsToValue(newValue);
91 if (newState == oldState)
94 if (ConditionChanged != null)
95 ConditionChanged(bindable, oldState, newState);