2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Diagnostics;
5 using System.Reflection;
6 using System.Runtime.CompilerServices;
7 using Tizen.NUI.Binding.Internals;
9 namespace Tizen.NUI.Binding
12 /// Provides a mechanism by which application developers can propagate changes that are made to data in one object to another, by enabling validation, type coercion, and an event system.
14 [EditorBrowsable(EditorBrowsableState.Never)]
15 public abstract class BindableObject : INotifyPropertyChanged, IDynamicResourceHandler
18 /// Implements the bound property whose interface is provided by the BindingContext property.
20 [EditorBrowsable(EditorBrowsableState.Never)]
21 public static readonly BindableProperty BindingContextProperty =
22 BindableProperty.Create("BindingContext", typeof(object), typeof(BindableObject), default(object),
23 BindingMode.OneWay, null, BindingContextPropertyChanged, null, null, BindingContextPropertyBindingChanging);
25 readonly List<BindablePropertyContext> _properties = new List<BindablePropertyContext>(4);
28 object _inheritedContext;
31 /// Gets or sets object that contains the properties that will be targeted by the bound properties that belong to this BindableObject.
33 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public object BindingContext
37 get { return _inheritedContext ?? GetValue(BindingContextProperty); }
38 set { SetValue(BindingContextProperty, value); }
41 void IDynamicResourceHandler.SetDynamicResource(BindableProperty property, string key)
43 SetDynamicResource(property, key, false);
47 /// Raised when a property has changed.
49 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public event PropertyChangedEventHandler PropertyChanged;
54 /// Raised whenever the BindingContext property changes.
56 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public event EventHandler BindingContextChanged;
60 internal void ClearValue(BindableProperty property, bool fromStyle)
62 ClearValue(property, fromStyle: fromStyle, checkAccess: true);
66 /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue.
68 /// <param name="property">The BindableProperty to clear</param>
69 internal void ClearValue(BindableProperty property)
71 ClearValue(property, fromStyle: false, checkAccess: true);
75 /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue for the property that is identified by propertyKey.
77 /// <param name="propertyKey">The BindablePropertyKey that identifies the BindableProperty to clear.</param>
78 internal void ClearValue(BindablePropertyKey propertyKey)
80 if (propertyKey == null)
81 throw new ArgumentNullException("propertyKey");
83 ClearValue(propertyKey.BindableProperty, fromStyle:false, checkAccess: false);
87 /// Return true if the target property exists and has been set.
89 /// <param name="targetProperty">The target property</param>
90 /// <returns>return true if the target property exists and has been set</returns>
91 internal bool IsSet(BindableProperty targetProperty)
93 if (targetProperty == null)
94 throw new ArgumentNullException(nameof(targetProperty));
96 var bpcontext = GetContext(targetProperty);
97 return bpcontext != null
98 && (bpcontext.Attributes & BindableContextAttributes.IsDefaultValue) == 0;
102 /// Returns the value that is contained the BindableProperty.
104 /// <param name="property">The BindableProperty for which to get the value.</param>
105 /// <returns>The value that is contained the BindableProperty</returns>
106 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 public object GetValue(BindableProperty property)
110 if (property == null)
111 throw new ArgumentNullException("property");
113 BindablePropertyContext context = property.DefaultValueCreator != null ? GetOrCreateContext(property) : GetContext(property);
116 return property.DefaultValue;
118 return context.Value;
122 /// Raised when a property is about to change.
124 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public event PropertyChangingEventHandler PropertyChanging;
129 /// Removes a previously set binding.
131 /// <param name="property">The BindableProperty from which to remove bindings.</param>
132 internal void RemoveBinding(BindableProperty property)
134 if (property == null)
135 throw new ArgumentNullException("property");
137 BindablePropertyContext context = GetContext(property);
138 if (context == null || context.Binding == null)
141 RemoveBinding(property, context);
145 /// Assigns a binding to a property.
147 /// <param name="targetProperty">The BindableProperty on which to set a binding.</param>
148 /// <param name="binding">The binding to set.</param>
149 internal void SetBinding(BindableProperty targetProperty, BindingBase binding)
151 SetBinding(targetProperty, binding, false);
154 private bool isCreateByXaml = false;
155 internal virtual bool IsCreateByXaml
159 return isCreateByXaml;
163 isCreateByXaml = value;
168 /// Sets the value of the specified property.
170 /// <param name="property">The BindableProperty on which to assign a value.</param>
171 /// <param name="value">The value to set.</param>
172 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public void SetValue(BindableProperty property, object value)
176 if (true == isCreateByXaml)
178 SetValue(property, value, false, true);
182 property.PropertyChanged?.Invoke(this, null, value);
186 internal void SetValueAndForceSendChangeSignal(BindableProperty property, object value)
188 if (property == null)
189 throw new ArgumentNullException("property");
191 if (true == isCreateByXaml)
193 if (property.IsReadOnly)
194 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
196 SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
197 SetValuePrivateFlags.ManuallySet | SetValuePrivateFlags.CheckAccess, true);
201 property.PropertyChanged?.Invoke(this, null, value);
206 /// Sets the value of the propertyKey.
208 /// <param name="propertyKey">The BindablePropertyKey on which to assign a value.</param>
209 /// <param name="value">The value to set.</param>
210 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public void SetValue(BindablePropertyKey propertyKey, object value)
214 if (propertyKey == null)
215 throw new ArgumentNullException("propertyKey");
217 SetValue(propertyKey.BindableProperty, value, false, false);
221 /// Set the inherited context to a neated element.
223 /// <param name="bindable">The object on which to set the inherited binding context.</param>
224 /// <param name="value">The inherited context to set.</param>
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public static void SetInheritedBindingContext(BindableObject bindable, object value)
228 BindablePropertyContext bpContext = bindable.GetContext(BindingContextProperty);
229 if (bpContext != null && ((bpContext.Attributes & BindableContextAttributes.IsManuallySet) != 0))
232 object oldContext = bindable._inheritedContext;
234 if (ReferenceEquals(oldContext, value))
237 if (bpContext != null && oldContext == null)
238 oldContext = bpContext.Value;
240 if (bpContext != null && bpContext.Binding != null)
242 bpContext.Binding.Context = value;
243 bindable._inheritedContext = null;
247 bindable._inheritedContext = value;
250 bindable.ApplyBindings(skipBindingContext:false, fromBindingContextChanged:true);
251 bindable.OnBindingContextChanged();
255 /// Apply the bindings to BindingContext.
257 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
258 [EditorBrowsable(EditorBrowsableState.Never)]
259 protected void ApplyBindings()
261 ApplyBindings(skipBindingContext: false, fromBindingContextChanged: false);
265 /// Override this method to execute an action when the BindingContext changes.
267 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 protected virtual void OnBindingContextChanged()
271 BindingContextChanged?.Invoke(this, EventArgs.Empty);
275 /// Call this method from a child class to notify that a change happened on a property.
277 /// <param name="propertyName">The name of the property that changed.</param>
278 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
281 => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
284 /// Call this method from a child class to notify that a change is going to happen on a property.
286 /// <param name="propertyName">The name of the property that is changing.</param>
287 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
288 [EditorBrowsable(EditorBrowsableState.Never)]
289 protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
290 => PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
293 /// Unapplies all previously set bindings.
295 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 protected void UnapplyBindings()
299 for (int i = 0, _propertiesCount = _properties.Count; i < _propertiesCount; i++) {
300 BindablePropertyContext context = _properties [i];
301 if (context.Binding == null)
304 context.Binding.Unapply();
308 internal bool GetIsBound(BindableProperty targetProperty)
310 if (targetProperty == null)
311 throw new ArgumentNullException("targetProperty");
313 BindablePropertyContext bpcontext = GetContext(targetProperty);
314 return bpcontext != null && bpcontext.Binding != null;
318 /// Returns the value that is contained the BindableProperty.
320 /// <param name="property0">The BindableProperty instance.</param>
321 /// <param name="property1">The BindableProperty instance.</param>
322 /// <returns>The value that is contained the BindableProperty</returns>
323 internal object[] GetValues(BindableProperty property0, BindableProperty property1)
325 var values = new object[2];
327 for (var i = 0; i < _properties.Count; i++)
329 BindablePropertyContext context = _properties[i];
331 if (ReferenceEquals(context.Property, property0))
333 values[0] = context.Value;
336 else if (ReferenceEquals(context.Property, property1))
338 values[1] = context.Value;
342 if (property0 == null && property1 == null)
346 if (!ReferenceEquals(property0, null))
347 values[0] = property0.DefaultValueCreator == null ? property0.DefaultValue : CreateAndAddContext(property0).Value;
348 if (!ReferenceEquals(property1, null))
349 values[1] = property1.DefaultValueCreator == null ? property1.DefaultValue : CreateAndAddContext(property1).Value;
355 /// Returns the value that is contained the BindableProperty.
357 /// <param name="property0">The BindableProperty instance.</param>
358 /// <param name="property1">The BindableProperty instance.</param>
359 /// <param name="property2">The BindableProperty instance.</param>
360 /// <returns>The value that is contained the BindableProperty</returns>
361 internal object[] GetValues(BindableProperty property0, BindableProperty property1, BindableProperty property2)
363 var values = new object[3];
365 for (var i = 0; i < _properties.Count; i++)
367 BindablePropertyContext context = _properties[i];
369 if (ReferenceEquals(context.Property, property0))
371 values[0] = context.Value;
374 else if (ReferenceEquals(context.Property, property1))
376 values[1] = context.Value;
379 else if (ReferenceEquals(context.Property, property2))
381 values[2] = context.Value;
385 if (property0 == null && property1 == null && property2 == null)
389 if (!ReferenceEquals(property0, null))
390 values[0] = property0.DefaultValueCreator == null ? property0.DefaultValue : CreateAndAddContext(property0).Value;
391 if (!ReferenceEquals(property1, null))
392 values[1] = property1.DefaultValueCreator == null ? property1.DefaultValue : CreateAndAddContext(property1).Value;
393 if (!ReferenceEquals(property2, null))
394 values[2] = property2.DefaultValueCreator == null ? property2.DefaultValue : CreateAndAddContext(property2).Value;
400 /// Returns the value that is contained the BindableProperty.
402 /// <param name="properties">The array of the BindableProperty instances</param>
403 /// <returns>The values that is contained the BindableProperty instances.</returns>
404 internal object[] GetValues(params BindableProperty[] properties)
406 var values = new object[properties.Length];
407 for (var i = 0; i < _properties.Count; i++) {
408 var context = _properties[i];
409 var index = properties.IndexOf(context.Property);
412 values[index] = context.Value;
414 for (var i = 0; i < values.Length; i++) {
415 if (!ReferenceEquals(values[i], null))
417 values[i] = properties[i].DefaultValueCreator == null ? properties[i].DefaultValue : CreateAndAddContext(properties[i]).Value;
422 internal virtual void OnRemoveDynamicResource(BindableProperty property)
426 internal virtual void OnSetDynamicResource(BindableProperty property, string key)
430 internal void RemoveDynamicResource(BindableProperty property)
432 if (property == null)
433 throw new ArgumentNullException("property");
435 OnRemoveDynamicResource(property);
436 BindablePropertyContext context = GetOrCreateContext(property);
437 context.Attributes &= ~BindableContextAttributes.IsDynamicResource;
440 internal void SetBinding(BindableProperty targetProperty, BindingBase binding, bool fromStyle)
442 if (targetProperty == null)
443 throw new ArgumentNullException("targetProperty");
445 throw new ArgumentNullException("binding");
447 if (fromStyle && !CanBeSetFromStyle(targetProperty))
450 var context = GetOrCreateContext(targetProperty);
452 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
454 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
456 if (context.Binding != null)
457 context.Binding.Unapply();
459 BindingBase oldBinding = context.Binding;
460 context.Binding = binding;
462 targetProperty.BindingChanging?.Invoke(this, oldBinding, binding);
464 binding.Apply(BindingContext, this, targetProperty);
467 bool CanBeSetFromStyle(BindableProperty property)
469 var context = GetContext(property);
472 if ((context.Attributes & BindableContextAttributes.IsSetFromStyle) == BindableContextAttributes.IsSetFromStyle)
474 if ((context.Attributes & BindableContextAttributes.IsDefaultValue) == BindableContextAttributes.IsDefaultValue)
476 if ((context.Attributes & BindableContextAttributes.IsDefaultValueCreated) == BindableContextAttributes.IsDefaultValueCreated)
481 internal void SetDynamicResource(BindableProperty property, string key)
483 SetDynamicResource(property, key, false);
486 internal void SetDynamicResource(BindableProperty property, string key, bool fromStyle)
488 if (property == null)
489 throw new ArgumentNullException(nameof(property));
490 if (string.IsNullOrEmpty(key))
491 throw new ArgumentNullException(nameof(key));
492 if (fromStyle && !CanBeSetFromStyle(property))
495 var context = GetOrCreateContext(property);
497 context.Attributes |= BindableContextAttributes.IsDynamicResource;
499 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
501 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
503 OnSetDynamicResource(property, key);
506 internal void SetValue(BindableProperty property, object value, bool fromStyle)
508 SetValue(property, value, fromStyle, true);
511 internal void SetValueCore(BindablePropertyKey propertyKey, object value, SetValueFlags attributes = SetValueFlags.None)
513 SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None, false);
517 /// For internal use.
519 /// <param name="property">The BindableProperty on which to assign a value.</param>
520 /// <param name="value">The value to set</param>
521 /// <param name="attributes">The set value flag</param>
522 [EditorBrowsable(EditorBrowsableState.Never)]
523 internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes = SetValueFlags.None)
525 SetValueCore(property, value, attributes, SetValuePrivateFlags.Default, false);
528 internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal)
530 bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0;
531 bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0;
532 bool silent = (privateAttributes & SetValuePrivateFlags.Silent) != 0;
533 bool fromStyle = (privateAttributes & SetValuePrivateFlags.FromStyle) != 0;
534 bool converted = (privateAttributes & SetValuePrivateFlags.Converted) != 0;
536 if (property == null)
537 throw new ArgumentNullException("property");
538 if (checkAccess && property.IsReadOnly)
540 Debug.WriteLine("Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName);
544 if (!converted && !property.TryConvert(ref value))
546 Console.WriteLine("SetValue", "Can not convert {0} to type '{1}'", value, property.ReturnType);
550 if (property.ValidateValue != null && !property.ValidateValue(this, value))
551 throw new ArgumentException("Value was an invalid value for " + property.PropertyName, "value");
553 if (property.CoerceValue != null)
554 value = property.CoerceValue(this, value);
556 BindablePropertyContext context = GetOrCreateContext(property);
558 context.Attributes |= BindableContextAttributes.IsManuallySet;
559 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
561 context.Attributes &= ~BindableContextAttributes.IsManuallySet;
564 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
565 // else omitted on purpose
567 bool currentlyApplying = _applying;
569 if ((context.Attributes & BindableContextAttributes.IsBeingSet) != 0)
571 Queue<SetValueArgs> delayQueue = context.DelayedSetters;
572 if (delayQueue == null)
573 context.DelayedSetters = delayQueue = new Queue<SetValueArgs>();
575 delayQueue.Enqueue(new SetValueArgs(property, context, value, currentlyApplying, attributes));
579 context.Attributes |= BindableContextAttributes.IsBeingSet;
580 SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent);
582 Queue<SetValueArgs> delayQueue = context.DelayedSetters;
583 if (delayQueue != null)
585 while (delayQueue.Count > 0)
587 SetValueArgs s = delayQueue.Dequeue();
588 SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes);
591 context.DelayedSetters = null;
594 context.Attributes &= ~BindableContextAttributes.IsBeingSet;
598 internal void ApplyBindings(bool skipBindingContext, bool fromBindingContextChanged)
600 var prop = _properties.ToArray();
601 for (int i = 0, propLength = prop.Length; i < propLength; i++) {
602 BindablePropertyContext context = prop [i];
603 BindingBase binding = context.Binding;
607 if (skipBindingContext && ReferenceEquals(context.Property, BindingContextProperty))
610 binding.Unapply(fromBindingContextChanged: fromBindingContextChanged);
611 binding.Apply(BindingContext, this, context.Property, fromBindingContextChanged: fromBindingContextChanged);
615 static void BindingContextPropertyBindingChanging(BindableObject bindable, BindingBase oldBindingBase, BindingBase newBindingBase)
617 object context = bindable._inheritedContext;
618 var oldBinding = oldBindingBase as Binding;
619 var newBinding = newBindingBase as Binding;
621 if (context == null && oldBinding != null)
622 context = oldBinding.Context;
623 if (context != null && newBinding != null)
624 newBinding.Context = context;
627 static void BindingContextPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
629 bindable._inheritedContext = null;
630 bindable.ApplyBindings(skipBindingContext: true, fromBindingContextChanged:true);
631 bindable.OnBindingContextChanged();
634 void ClearValue(BindableProperty property, bool fromStyle, bool checkAccess)
636 if (property == null)
637 throw new ArgumentNullException(nameof(property));
639 if (checkAccess && property.IsReadOnly)
640 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
642 BindablePropertyContext bpcontext = GetContext(property);
643 if (bpcontext == null)
646 if (fromStyle && !CanBeSetFromStyle(property))
649 object original = bpcontext.Value;
651 object newValue = property.GetDefaultValue(this);
653 bool same = Equals(original, newValue);
656 property.PropertyChanging?.Invoke(this, original, newValue);
658 OnPropertyChanging(property.PropertyName);
661 bpcontext.Attributes &= ~BindableContextAttributes.IsManuallySet;
662 bpcontext.Value = newValue;
663 if (property.DefaultValueCreator == null)
664 bpcontext.Attributes |= BindableContextAttributes.IsDefaultValue;
666 bpcontext.Attributes |= BindableContextAttributes.IsDefaultValueCreated;
670 OnPropertyChanged(property.PropertyName);
671 property.PropertyChanged?.Invoke(this, original, newValue);
675 [MethodImpl(MethodImplOptions.AggressiveInlining)]
676 BindablePropertyContext CreateAndAddContext(BindableProperty property)
678 var context = new BindablePropertyContext { Property = property, Value = property.DefaultValueCreator != null ? property.DefaultValueCreator(this) : property.DefaultValue };
680 if (property.DefaultValueCreator == null)
681 context.Attributes = BindableContextAttributes.IsDefaultValue;
683 context.Attributes = BindableContextAttributes.IsDefaultValueCreated;
685 _properties.Add(context);
689 [MethodImpl(MethodImplOptions.AggressiveInlining)]
690 BindablePropertyContext GetContext(BindableProperty property)
692 List<BindablePropertyContext> properties = _properties;
694 for (var i = 0; i < properties.Count; i++)
696 BindablePropertyContext context = properties[i];
697 if (ReferenceEquals(context.Property, property))
704 [MethodImpl(MethodImplOptions.AggressiveInlining)]
705 BindablePropertyContext GetOrCreateContext(BindableProperty property)
707 BindablePropertyContext context = GetContext(property);
710 context = CreateAndAddContext(property);
712 else if (property.DefaultValueCreator != null )
714 context.Value = property.DefaultValueCreator(this); //Update Value from dali
720 void RemoveBinding(BindableProperty property, BindablePropertyContext context)
722 context.Binding.Unapply();
724 property.BindingChanging?.Invoke(this, context.Binding, null);
726 context.Binding = null;
729 void SetValue(BindableProperty property, object value, bool fromStyle, bool checkAccess)
731 if (property == null)
732 throw new ArgumentNullException("property");
734 if (checkAccess && property.IsReadOnly)
735 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
737 if (fromStyle && !CanBeSetFromStyle(property))
740 SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
741 (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0),
745 void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false)
747 object original = context.Value;
748 bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0;
749 bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0;
750 bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0;
751 bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0;
753 bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original);
754 if (!silent && (!same || raiseOnEqual))
756 property.PropertyChanging?.Invoke(this, original, value);
758 OnPropertyChanging(property.PropertyName);
761 if (!same || raiseOnEqual)
763 context.Value = value;
766 context.Attributes &= ~BindableContextAttributes.IsDefaultValue;
767 context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated;
769 if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources)
770 RemoveDynamicResource(property);
772 BindingBase binding = context.Binding;
775 if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay)
777 RemoveBinding(property, context);
784 if ((!same || raiseOnEqual))
786 property.PropertyChanged?.Invoke(this, original, value);
788 if (binding != null && !currentlyApplying)
795 OnPropertyChanged(property.PropertyName);
797 else if (true == same && true == forceSendChangeSignal)
799 if (binding != null && !currentlyApplying)
806 OnPropertyChanged(property.PropertyName);
812 enum BindableContextAttributes
814 IsManuallySet = 1 << 0,
816 IsDynamicResource = 1 << 2,
817 IsSetFromStyle = 1 << 3,
818 IsDefaultValue = 1 << 4,
819 IsDefaultValueCreated = 1 << 5,
822 class BindablePropertyContext
824 public BindableContextAttributes Attributes;
825 public BindingBase Binding;
826 public Queue<SetValueArgs> DelayedSetters;
827 public BindableProperty Property;
832 internal enum SetValuePrivateFlags
835 CheckAccess = 1 << 0,
837 ManuallySet = 1 << 2,
840 Default = CheckAccess
845 public readonly SetValueFlags Attributes;
846 public readonly BindablePropertyContext Context;
847 public readonly bool CurrentlyApplying;
848 public readonly BindableProperty Property;
849 public readonly object Value;
851 public SetValueArgs(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes)
856 CurrentlyApplying = currentlyApplying;
857 Attributes = attributes;
863 namespace Tizen.NUI.Binding.Internals
866 /// SetValueFlags. For internal use.
869 [EditorBrowsable(EditorBrowsableState.Never)]
870 public enum SetValueFlags
875 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
876 [EditorBrowsable(EditorBrowsableState.Never)]
880 /// Clear OneWay bindings.
882 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
883 [EditorBrowsable(EditorBrowsableState.Never)]
884 ClearOneWayBindings = 1 << 0,
887 /// Clear TwoWay bindings.
889 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
890 [EditorBrowsable(EditorBrowsableState.Never)]
891 ClearTwoWayBindings = 1 << 1,
894 /// Clear dynamic resource.
896 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
897 [EditorBrowsable(EditorBrowsableState.Never)]
898 ClearDynamicResource = 1 << 2,
903 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
904 [EditorBrowsable(EditorBrowsableState.Never)]
905 RaiseOnEqual = 1 << 3