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(nameof(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;
53 /// <summary>Whether to allow null value when <seealso cref="CopyFrom"/>.</summary>
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 protected static bool AllowNullCopy { get; set; } = false;
57 /// <summary>Copy properties of other ViewStyle to this.</summary>
58 /// <param name="other">The other BindableProperty merge to this.</param>
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public virtual void CopyFrom(BindableObject other)
62 if (null == other) return;
64 Type type1 = this.GetType();
65 BindableProperty.GetBindablePropertysOfType(type1, out var nameToBindableProperty1);
67 Type type2 = other.GetType();
68 BindableProperty.GetBindablePropertysOfType(type2, out var nameToBindableProperty2);
70 if (null != nameToBindableProperty1)
72 foreach (KeyValuePair<string, BindableProperty> keyValuePair in nameToBindableProperty1)
74 nameToBindableProperty2.TryGetValue(keyValuePair.Key, out var bindableProperty);
76 if (null != bindableProperty)
78 object value = other.GetValue(bindableProperty);
80 if (AllowNullCopy || null != value)
82 SetValue(keyValuePair.Value, value);
90 /// Raised whenever the BindingContext property changes.
92 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 public event EventHandler BindingContextChanged;
96 internal void ClearValue(BindableProperty property, bool fromStyle)
98 ClearValue(property, fromStyle: fromStyle, checkAccess: true);
102 /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue.
104 /// <param name="property">The BindableProperty to clear</param>
105 internal void ClearValue(BindableProperty property)
107 ClearValue(property, fromStyle: false, checkAccess: true);
111 /// Clears any value set by Tizen.NUI.Xaml.BindableObject.SetValue for the property that is identified by propertyKey.
113 /// <param name="propertyKey">The BindablePropertyKey that identifies the BindableProperty to clear.</param>
114 internal void ClearValue(BindablePropertyKey propertyKey)
116 if (propertyKey == null)
117 throw new ArgumentNullException(nameof(propertyKey));
119 ClearValue(propertyKey.BindableProperty, fromStyle:false, checkAccess: false);
123 /// Return true if the target property exists and has been set.
125 /// <param name="targetProperty">The target property</param>
126 /// <returns>return true if the target property exists and has been set</returns>
127 internal bool IsSet(BindableProperty targetProperty)
129 if (targetProperty == null)
130 throw new ArgumentNullException(nameof(targetProperty));
132 var bpcontext = GetContext(targetProperty);
133 return bpcontext != null
134 && (bpcontext.Attributes & BindableContextAttributes.IsDefaultValue) == 0;
138 /// Returns the value that is contained the BindableProperty.
140 /// <param name="property">The BindableProperty for which to get the value.</param>
141 /// <returns>The value that is contained the BindableProperty</returns>
142 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public object GetValue(BindableProperty property)
146 if (property == null)
147 throw new ArgumentNullException(nameof(property));
149 BindablePropertyContext context = property.DefaultValueCreator != null ? GetOrCreateContext(property) : GetContext(property);
152 return property.DefaultValue;
154 return context.Value;
158 /// Raised when a property is about to change.
160 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public event PropertyChangingEventHandler PropertyChanging;
165 /// Removes a previously set binding.
167 /// <param name="property">The BindableProperty from which to remove bindings.</param>
168 internal void RemoveBinding(BindableProperty property)
170 if (property == null)
171 throw new ArgumentNullException(nameof(property));
173 BindablePropertyContext context = GetContext(property);
174 if (context == null || context.Binding == null)
177 RemoveBinding(property, context);
181 /// Assigns a binding to a property.
183 /// <param name="targetProperty">The BindableProperty on which to set a binding.</param>
184 /// <param name="binding">The binding to set.</param>
185 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public void SetBinding(BindableProperty targetProperty, BindingBase binding)
189 SetBinding(targetProperty, binding, false);
192 private bool isCreateByXaml = false;
193 /// Only used by the IL of xaml, will never changed to not hidden.
194 [EditorBrowsable(EditorBrowsableState.Never)]
195 public virtual bool IsCreateByXaml
199 return isCreateByXaml;
203 isCreateByXaml = value;
208 /// Sets the value of the specified property.
210 /// <param name="property">The BindableProperty on which to assign a value.</param>
211 /// <param name="value">The value to set.</param>
212 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public void SetValue(BindableProperty property, object value)
216 if (true == isCreateByXaml)
218 SetValue(property, value, false, true);
222 property.PropertyChanged?.Invoke(this, null, value);
224 OnPropertyChanged(property.PropertyName);
228 internal void SetValueAndForceSendChangeSignal(BindableProperty property, object value)
230 if (property == null)
231 throw new ArgumentNullException(nameof(property));
233 if (true == isCreateByXaml)
235 if (property.IsReadOnly)
236 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
238 SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
239 SetValuePrivateFlags.ManuallySet | SetValuePrivateFlags.CheckAccess, true);
243 property.PropertyChanged?.Invoke(this, null, value);
248 /// Sets the value of the propertyKey.
250 /// <param name="propertyKey">The BindablePropertyKey on which to assign a value.</param>
251 /// <param name="value">The value to set.</param>
252 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public void SetValue(BindablePropertyKey propertyKey, object value)
256 if (propertyKey == null)
257 throw new ArgumentNullException(nameof(propertyKey));
259 SetValue(propertyKey.BindableProperty, value, false, false);
263 /// Set the inherited context to a neated element.
265 /// <param name="bindable">The object on which to set the inherited binding context.</param>
266 /// <param name="value">The inherited context to set.</param>
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 public static void SetInheritedBindingContext(BindableObject bindable, object value)
270 BindablePropertyContext bpContext = bindable.GetContext(BindingContextProperty);
271 if (bpContext != null && ((bpContext.Attributes & BindableContextAttributes.IsManuallySet) != 0))
274 object oldContext = bindable._inheritedContext;
276 if (ReferenceEquals(oldContext, value))
279 if (bpContext != null && oldContext == null)
280 oldContext = bpContext.Value;
282 if (bpContext != null && bpContext.Binding != null)
284 bpContext.Binding.Context = value;
285 bindable._inheritedContext = null;
289 bindable._inheritedContext = value;
292 bindable.ApplyBindings(skipBindingContext:false, fromBindingContextChanged:true);
293 bindable.OnBindingContextChanged();
297 /// Apply the bindings to BindingContext.
299 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 protected void ApplyBindings()
303 ApplyBindings(skipBindingContext: false, fromBindingContextChanged: false);
307 /// Override this method to execute an action when the BindingContext changes.
309 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 protected virtual void OnBindingContextChanged()
313 BindingContextChanged?.Invoke(this, EventArgs.Empty);
317 /// Call this method from a child class to notify that a change happened on a property.
319 /// <param name="propertyName">The name of the property that changed.</param>
320 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
321 [EditorBrowsable(EditorBrowsableState.Never)]
322 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
323 => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
326 /// Call this method from a child class to notify that a change is going to happen on a property.
328 /// <param name="propertyName">The name of the property that is changing.</param>
329 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
330 [EditorBrowsable(EditorBrowsableState.Never)]
331 protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
332 => PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
335 /// Unapplies all previously set bindings.
337 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
338 [EditorBrowsable(EditorBrowsableState.Never)]
339 protected void UnapplyBindings()
341 for (int i = 0, _propertiesCount = _properties.Count; i < _propertiesCount; i++) {
342 BindablePropertyContext context = _properties [i];
343 if (context.Binding == null)
346 context.Binding.Unapply();
350 internal bool GetIsBound(BindableProperty targetProperty)
352 if (targetProperty == null)
353 throw new ArgumentNullException(nameof(targetProperty));
355 BindablePropertyContext bpcontext = GetContext(targetProperty);
356 return bpcontext != null && bpcontext.Binding != null;
360 /// Returns the value that is contained the BindableProperty.
362 /// <param name="property0">The BindableProperty instance.</param>
363 /// <param name="property1">The BindableProperty instance.</param>
364 /// <returns>The value that is contained the BindableProperty</returns>
365 internal object[] GetValues(BindableProperty property0, BindableProperty property1)
367 var values = new object[2];
369 for (var i = 0; i < _properties.Count; i++)
371 BindablePropertyContext context = _properties[i];
373 if (ReferenceEquals(context.Property, property0))
375 values[0] = context.Value;
378 else if (ReferenceEquals(context.Property, property1))
380 values[1] = context.Value;
384 if (property0 == null && property1 == null)
388 if (!ReferenceEquals(property0, null))
389 values[0] = property0.DefaultValueCreator == null ? property0.DefaultValue : CreateAndAddContext(property0).Value;
390 if (!ReferenceEquals(property1, null))
391 values[1] = property1.DefaultValueCreator == null ? property1.DefaultValue : CreateAndAddContext(property1).Value;
397 /// Returns the value that is contained the BindableProperty.
399 /// <param name="property0">The BindableProperty instance.</param>
400 /// <param name="property1">The BindableProperty instance.</param>
401 /// <param name="property2">The BindableProperty instance.</param>
402 /// <returns>The value that is contained the BindableProperty</returns>
403 internal object[] GetValues(BindableProperty property0, BindableProperty property1, BindableProperty property2)
405 var values = new object[3];
407 for (var i = 0; i < _properties.Count; i++)
409 BindablePropertyContext context = _properties[i];
411 if (ReferenceEquals(context.Property, property0))
413 values[0] = context.Value;
416 else if (ReferenceEquals(context.Property, property1))
418 values[1] = context.Value;
421 else if (ReferenceEquals(context.Property, property2))
423 values[2] = context.Value;
427 if (property0 == null && property1 == null && property2 == null)
431 if (!ReferenceEquals(property0, null))
432 values[0] = property0.DefaultValueCreator == null ? property0.DefaultValue : CreateAndAddContext(property0).Value;
433 if (!ReferenceEquals(property1, null))
434 values[1] = property1.DefaultValueCreator == null ? property1.DefaultValue : CreateAndAddContext(property1).Value;
435 if (!ReferenceEquals(property2, null))
436 values[2] = property2.DefaultValueCreator == null ? property2.DefaultValue : CreateAndAddContext(property2).Value;
442 /// Returns the value that is contained the BindableProperty.
444 /// <param name="properties">The array of the BindableProperty instances</param>
445 /// <returns>The values that is contained the BindableProperty instances.</returns>
446 internal object[] GetValues(params BindableProperty[] properties)
448 var values = new object[properties.Length];
449 for (var i = 0; i < _properties.Count; i++) {
450 var context = _properties[i];
451 var index = properties.IndexOf(context.Property);
454 values[index] = context.Value;
456 for (var i = 0; i < values.Length; i++) {
457 if (!ReferenceEquals(values[i], null))
459 values[i] = properties[i].DefaultValueCreator == null ? properties[i].DefaultValue : CreateAndAddContext(properties[i]).Value;
464 internal virtual void OnRemoveDynamicResource(BindableProperty property)
468 internal virtual void OnSetDynamicResource(BindableProperty property, string key)
472 internal void RemoveDynamicResource(BindableProperty property)
474 if (property == null)
475 throw new ArgumentNullException(nameof(property));
477 OnRemoveDynamicResource(property);
478 BindablePropertyContext context = GetOrCreateContext(property);
479 context.Attributes &= ~BindableContextAttributes.IsDynamicResource;
482 internal void SetBinding(BindableProperty targetProperty, BindingBase binding, bool fromStyle)
484 if (targetProperty == null)
485 throw new ArgumentNullException(nameof(targetProperty));
487 throw new ArgumentNullException(nameof(binding));
489 if (fromStyle && !CanBeSetFromStyle(targetProperty))
492 var context = GetOrCreateContext(targetProperty);
494 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
496 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
498 if (context.Binding != null)
499 context.Binding.Unapply();
501 BindingBase oldBinding = context.Binding;
502 context.Binding = binding;
504 targetProperty.BindingChanging?.Invoke(this, oldBinding, binding);
506 binding.Apply(BindingContext, this, targetProperty);
509 bool CanBeSetFromStyle(BindableProperty property)
511 var context = GetContext(property);
514 if ((context.Attributes & BindableContextAttributes.IsSetFromStyle) == BindableContextAttributes.IsSetFromStyle)
516 if ((context.Attributes & BindableContextAttributes.IsDefaultValue) == BindableContextAttributes.IsDefaultValue)
518 if ((context.Attributes & BindableContextAttributes.IsDefaultValueCreated) == BindableContextAttributes.IsDefaultValueCreated)
523 internal void SetDynamicResource(BindableProperty property, string key)
525 SetDynamicResource(property, key, false);
528 internal void SetDynamicResource(BindableProperty property, string key, bool fromStyle)
530 if (property == null)
531 throw new ArgumentNullException(nameof(property));
532 if (string.IsNullOrEmpty(key))
533 throw new ArgumentNullException(nameof(key));
534 if (fromStyle && !CanBeSetFromStyle(property))
537 var context = GetOrCreateContext(property);
539 context.Attributes |= BindableContextAttributes.IsDynamicResource;
541 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
543 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
545 OnSetDynamicResource(property, key);
548 internal void SetValue(BindableProperty property, object value, bool fromStyle)
550 SetValue(property, value, fromStyle, true);
553 internal void SetValueCore(BindablePropertyKey propertyKey, object value, SetValueFlags attributes = SetValueFlags.None)
555 SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None, false);
559 /// For internal use.
561 /// <param name="property">The BindableProperty on which to assign a value.</param>
562 /// <param name="value">The value to set</param>
563 /// <param name="attributes">The set value flag</param>
564 [EditorBrowsable(EditorBrowsableState.Never)]
565 internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes = SetValueFlags.None)
567 SetValueCore(property, value, attributes, SetValuePrivateFlags.Default, false);
570 internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal)
572 bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0;
573 bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0;
574 bool silent = (privateAttributes & SetValuePrivateFlags.Silent) != 0;
575 bool fromStyle = (privateAttributes & SetValuePrivateFlags.FromStyle) != 0;
576 bool converted = (privateAttributes & SetValuePrivateFlags.Converted) != 0;
578 if (property == null)
579 throw new ArgumentNullException(nameof(property));
580 if (checkAccess && property.IsReadOnly)
582 Debug.WriteLine("Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName);
586 if (!converted && !property.TryConvert(ref value))
588 Console.WriteLine("SetValue", "Can not convert {0} to type '{1}'", value, property.ReturnType);
592 if (property.ValidateValue != null && !property.ValidateValue(this, value))
593 throw new ArgumentException("Value was an invalid value for " + property.PropertyName, nameof(value));
595 if (property.CoerceValue != null)
596 value = property.CoerceValue(this, value);
598 BindablePropertyContext context = GetOrCreateContext(property);
600 context.Attributes |= BindableContextAttributes.IsManuallySet;
601 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
603 context.Attributes &= ~BindableContextAttributes.IsManuallySet;
606 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
607 // else omitted on purpose
609 bool currentlyApplying = _applying;
611 if ((context.Attributes & BindableContextAttributes.IsBeingSet) != 0)
613 Queue<SetValueArgs> delayQueue = context.DelayedSetters;
614 if (delayQueue == null)
615 context.DelayedSetters = delayQueue = new Queue<SetValueArgs>();
617 delayQueue.Enqueue(new SetValueArgs(property, context, value, currentlyApplying, attributes));
621 context.Attributes |= BindableContextAttributes.IsBeingSet;
622 SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent);
624 Queue<SetValueArgs> delayQueue = context.DelayedSetters;
625 if (delayQueue != null)
627 while (delayQueue.Count > 0)
629 SetValueArgs s = delayQueue.Dequeue();
630 SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes);
633 context.DelayedSetters = null;
636 context.Attributes &= ~BindableContextAttributes.IsBeingSet;
640 internal void ApplyBindings(bool skipBindingContext, bool fromBindingContextChanged)
642 var prop = _properties.ToArray();
643 for (int i = 0, propLength = prop.Length; i < propLength; i++) {
644 BindablePropertyContext context = prop [i];
645 BindingBase binding = context.Binding;
649 if (skipBindingContext && ReferenceEquals(context.Property, BindingContextProperty))
652 binding.Unapply(fromBindingContextChanged: fromBindingContextChanged);
653 binding.Apply(BindingContext, this, context.Property, fromBindingContextChanged: fromBindingContextChanged);
657 static void BindingContextPropertyBindingChanging(BindableObject bindable, BindingBase oldBindingBase, BindingBase newBindingBase)
659 object context = bindable._inheritedContext;
660 var oldBinding = oldBindingBase as Binding;
661 var newBinding = newBindingBase as Binding;
663 if (context == null && oldBinding != null)
664 context = oldBinding.Context;
665 if (context != null && newBinding != null)
666 newBinding.Context = context;
669 static void BindingContextPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
671 bindable._inheritedContext = null;
672 bindable.ApplyBindings(skipBindingContext: true, fromBindingContextChanged:true);
673 bindable.OnBindingContextChanged();
676 void ClearValue(BindableProperty property, bool fromStyle, bool checkAccess)
678 if (property == null)
679 throw new ArgumentNullException(nameof(property));
681 if (checkAccess && property.IsReadOnly)
682 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
684 BindablePropertyContext bpcontext = GetContext(property);
685 if (bpcontext == null)
688 if (fromStyle && !CanBeSetFromStyle(property))
691 object original = bpcontext.Value;
693 object newValue = property.GetDefaultValue(this);
695 bool same = Equals(original, newValue);
698 property.PropertyChanging?.Invoke(this, original, newValue);
700 OnPropertyChanging(property.PropertyName);
703 bpcontext.Attributes &= ~BindableContextAttributes.IsManuallySet;
704 bpcontext.Value = newValue;
705 if (property.DefaultValueCreator == null)
706 bpcontext.Attributes |= BindableContextAttributes.IsDefaultValue;
708 bpcontext.Attributes |= BindableContextAttributes.IsDefaultValueCreated;
712 OnPropertyChanged(property.PropertyName);
713 property.PropertyChanged?.Invoke(this, original, newValue);
717 [MethodImpl(MethodImplOptions.AggressiveInlining)]
718 BindablePropertyContext CreateAndAddContext(BindableProperty property)
720 var context = new BindablePropertyContext { Property = property, Value = property.DefaultValueCreator != null ? property.DefaultValueCreator(this) : property.DefaultValue };
722 if (property.DefaultValueCreator == null)
723 context.Attributes = BindableContextAttributes.IsDefaultValue;
725 context.Attributes = BindableContextAttributes.IsDefaultValueCreated;
727 _properties.Add(context);
731 [MethodImpl(MethodImplOptions.AggressiveInlining)]
732 BindablePropertyContext GetContext(BindableProperty property)
734 List<BindablePropertyContext> properties = _properties;
736 for (var i = 0; i < properties.Count; i++)
738 BindablePropertyContext context = properties[i];
739 if (ReferenceEquals(context.Property, property))
746 [MethodImpl(MethodImplOptions.AggressiveInlining)]
747 BindablePropertyContext GetOrCreateContext(BindableProperty property)
749 BindablePropertyContext context = GetContext(property);
752 context = CreateAndAddContext(property);
754 else if (property.DefaultValueCreator != null )
756 context.Value = property.DefaultValueCreator(this); //Update Value from dali
762 void RemoveBinding(BindableProperty property, BindablePropertyContext context)
764 context.Binding.Unapply();
766 property.BindingChanging?.Invoke(this, context.Binding, null);
768 context.Binding = null;
771 void SetValue(BindableProperty property, object value, bool fromStyle, bool checkAccess)
773 if (property == null)
774 throw new ArgumentNullException(nameof(property));
776 if (checkAccess && property.IsReadOnly)
777 throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
779 if (fromStyle && !CanBeSetFromStyle(property))
782 SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
783 (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0),
787 void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false)
789 object original = context.Value;
790 bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0;
791 bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0;
792 bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0;
793 bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0;
795 bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original);
796 if (!silent && (!same || raiseOnEqual))
798 property.PropertyChanging?.Invoke(this, original, value);
800 OnPropertyChanging(property.PropertyName);
803 if (!same || raiseOnEqual)
805 context.Value = value;
808 context.Attributes &= ~BindableContextAttributes.IsDefaultValue;
809 context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated;
811 if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources)
812 RemoveDynamicResource(property);
814 BindingBase binding = context.Binding;
817 if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay)
819 RemoveBinding(property, context);
826 if ((!same || raiseOnEqual))
828 property.PropertyChanged?.Invoke(this, original, value);
830 if (binding != null && !currentlyApplying)
837 OnPropertyChanged(property.PropertyName);
839 else if (true == same && true == forceSendChangeSignal)
841 if (binding != null && !currentlyApplying)
848 OnPropertyChanged(property.PropertyName);
854 enum BindableContextAttributes
856 IsManuallySet = 1 << 0,
858 IsDynamicResource = 1 << 2,
859 IsSetFromStyle = 1 << 3,
860 IsDefaultValue = 1 << 4,
861 IsDefaultValueCreated = 1 << 5,
864 class BindablePropertyContext
866 public BindableContextAttributes Attributes;
867 public BindingBase Binding;
868 public Queue<SetValueArgs> DelayedSetters;
869 public BindableProperty Property;
874 internal enum SetValuePrivateFlags
877 CheckAccess = 1 << 0,
879 ManuallySet = 1 << 2,
882 Default = CheckAccess
887 public readonly SetValueFlags Attributes;
888 public readonly BindablePropertyContext Context;
889 public readonly bool CurrentlyApplying;
890 public readonly BindableProperty Property;
891 public readonly object Value;
893 public SetValueArgs(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes)
898 CurrentlyApplying = currentlyApplying;
899 Attributes = attributes;
905 namespace Tizen.NUI.Binding.Internals
908 /// SetValueFlags. For internal use.
911 [EditorBrowsable(EditorBrowsableState.Never)]
912 public enum SetValueFlags
917 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
918 [EditorBrowsable(EditorBrowsableState.Never)]
922 /// Clear OneWay bindings.
924 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
925 [EditorBrowsable(EditorBrowsableState.Never)]
926 ClearOneWayBindings = 1 << 0,
929 /// Clear TwoWay bindings.
931 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
932 [EditorBrowsable(EditorBrowsableState.Never)]
933 ClearTwoWayBindings = 1 << 1,
936 /// Clear dynamic resource.
938 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
939 [EditorBrowsable(EditorBrowsableState.Never)]
940 ClearDynamicResource = 1 << 2,
945 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
946 [EditorBrowsable(EditorBrowsableState.Never)]
947 RaiseOnEqual = 1 << 3