void RemoveBinding(BindableProperty property, BindablePropertyContext context) { context.Binding.Unapply(); property.BindingChanging?.Invoke(this, context.Binding, null); context.Binding = null; }
public SetValueArgs(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes) { Property = property; Context = context; Value = value; CurrentlyApplying = currentlyApplying; Attributes = attributes; }
void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent = false) { object original = context.Value; bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0; bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0; bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0; bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0; bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original); if (!silent && (!same || raiseOnEqual)) { property.PropertyChanging?.Invoke(this, original, value); OnPropertyChanging(property.PropertyName); } if (!same || raiseOnEqual) { context.Value = value; } context.Attributes &= ~BindableContextAttributes.IsDefaultValue; context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated; if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources) { RemoveDynamicResource(property); } BindingBase binding = context.Binding; if (binding != null) { if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay) { RemoveBinding(property, context); binding = null; } } if (!silent) { if ((!same || raiseOnEqual)) { property.PropertyChanged?.Invoke(this, original, value); if (binding != null && !currentlyApplying) { _applying = true; binding.Apply(true); _applying = false; } OnPropertyChanged(property.PropertyName); } } }
void ClearValue(BindableProperty property, bool fromStyle, bool checkAccess) { if (property == null) { throw new ArgumentNullException(nameof(property)); } if (checkAccess && property.IsReadOnly) { throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName)); } BindablePropertyContext bpcontext = GetContext(property); if (bpcontext == null) { return; } if (fromStyle && !CanBeSetFromStyle(property)) { return; } object original = bpcontext.Value; object newValue = property.GetDefaultValue(this); bool same = Equals(original, newValue); if (!same) { property.PropertyChanging?.Invoke(this, original, newValue); OnPropertyChanging(property.PropertyName); } bpcontext.Attributes &= ~BindableContextAttributes.IsManuallySet; bpcontext.Value = newValue; if (property.DefaultValueCreator == null) { bpcontext.Attributes |= BindableContextAttributes.IsDefaultValue; } else { bpcontext.Attributes |= BindableContextAttributes.IsDefaultValueCreated; } if (!same) { OnPropertyChanged(property.PropertyName); OnPropertyChangedWithData(property); property.PropertyChanged?.Invoke(this, original, newValue); } }
void RemoveBinding(BindableProperty property, BindablePropertyContext context) { context.Binding.Unapply(); if (property.BindingChanging != null) { property.BindingChanging(this, context.Binding, null); } context.Binding = null; }
internal bool GetIsBound(BindableProperty targetProperty) { if (targetProperty == null) { throw new ArgumentNullException(nameof(targetProperty)); } BindablePropertyContext bpcontext = GetContext(targetProperty); return(bpcontext != null && bpcontext.Binding != null); }
BindablePropertyContext GetOrCreateContext(BindableProperty property) { BindablePropertyContext context = GetContext(property); if (context == null) { context = CreateAndAddContext(property); } return(context); }
internal void RemoveDynamicResource(BindableProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } OnRemoveDynamicResource(property); BindablePropertyContext context = GetOrCreateContext(property); context.Attributes &= ~BindableContextAttributes.IsDynamicResource; }
protected void UnapplyBindings() { for (int i = 0, _propertiesCount = _properties.Count; i < _propertiesCount; i++) { BindablePropertyContext context = _properties[i]; if (context.Binding == null) { continue; } context.Binding.Unapply(); } }
BindablePropertyContext CreateAndAddContext(BindableProperty property) { var context = new BindablePropertyContext { Property = property, Value = property.DefaultValueCreator != null?property.DefaultValueCreator(this) : property.DefaultValue }; if (property.DefaultValueCreator != null) { context.Attributes = BindableContextAttributes.IsDefaultValue; } _properties.Add(context); return(context); }
/// <summary> /// Force notify the listener. /// </summary> /// <param name="property">The BindableProperty on which to assign a value.</param> /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. public void ForceNotify(BindableProperty property) { BindablePropertyContext context = GetOrCreateContext(property); BindingBase binding = context.Binding; if (binding != null) { _applying = true; binding.Apply(true); _applying = false; } OnPropertyChanged(property.PropertyName); }
BindablePropertyContext GetOrCreateContext(BindableProperty property) { BindablePropertyContext context = GetContext(property); if (context == null) { context = CreateAndAddContext(property); } else if (property.DefaultValueCreator != null) { context.Value = property.DefaultValueCreator(this); //Update Value from dali }//added by xb.teng return(context); }
BindablePropertyContext GetContext(BindableProperty property) { List <BindablePropertyContext> properties = _properties; for (var i = 0; i < properties.Count; i++) { BindablePropertyContext context = properties[i]; if (ReferenceEquals(context.Property, property)) { return(context); } } return(null); }
void ClearValue(BindableProperty property, bool checkaccess) { if (property == null) { throw new ArgumentNullException("property"); } if (checkaccess && property.IsReadOnly) { throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName)); } BindablePropertyContext bpcontext = GetContext(property); if (bpcontext == null) { return; } object original = bpcontext.Value; object newValue = property.GetDefaultValue(this); bool same = Equals(original, newValue); if (!same) { if (property.PropertyChanging != null) { property.PropertyChanging(this, original, newValue); } OnPropertyChanging(property.PropertyName); } bpcontext.Attributes &= ~BindableContextAttributes.IsManuallySet; bpcontext.Value = newValue; bpcontext.Attributes |= BindableContextAttributes.IsDefaultValue; if (!same) { OnPropertyChanged(property.PropertyName); if (property.PropertyChanged != null) { property.PropertyChanged(this, original, newValue); } } }
/// <summary> /// Removes a previously set binding. /// </summary> /// <param name="property">The BindableProperty from which to remove bindings.</param> internal void RemoveBinding(BindableProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } BindablePropertyContext context = GetContext(property); if (context == null || context.Binding == null) { return; } RemoveBinding(property, context); }
public object GetValue(BindableProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } BindablePropertyContext context = property.DefaultValueCreator != null?GetOrCreateContext(property) : GetContext(property); if (context == null) { return(property.DefaultValue); } return(context.Value); }
/// <summary> /// Returns the value that is contained the BindableProperty. /// </summary> /// <param name="property0">The BindableProperty instance.</param> /// <param name="property1">The BindableProperty instance.</param> /// <param name="property2">The BindableProperty instance.</param> /// <returns>The value that is contained the BindableProperty</returns> internal object[] GetValues(BindableProperty property0, BindableProperty property1, BindableProperty property2) { var values = new object[3]; for (var i = 0; i < _properties.Count; i++) { BindablePropertyContext context = _properties[i]; if (ReferenceEquals(context.Property, property0)) { values[0] = context.Value; property0 = null; } else if (ReferenceEquals(context.Property, property1)) { values[1] = context.Value; property1 = null; } else if (ReferenceEquals(context.Property, property2)) { values[2] = context.Value; property2 = null; } if (property0 == null && property1 == null && property2 == null) { return(values); } } if (!ReferenceEquals(property0, null)) { values[0] = property0.DefaultValueCreator == null ? property0.DefaultValue : CreateAndAddContext(property0).Value; } if (!ReferenceEquals(property1, null)) { values[1] = property1.DefaultValueCreator == null ? property1.DefaultValue : CreateAndAddContext(property1).Value; } if (!ReferenceEquals(property2, null)) { values[2] = property2.DefaultValueCreator == null ? property2.DefaultValue : CreateAndAddContext(property2).Value; } return(values); }
internal void SetBinding(BindableProperty targetProperty, BindingBase binding, bool fromStyle) { if (targetProperty == null) { throw new ArgumentNullException("targetProperty"); } if (binding == null) { throw new ArgumentNullException("binding"); } BindablePropertyContext context = null; if (fromStyle && (context = GetContext(targetProperty)) != null && (context.Attributes & BindableContextAttributes.IsDefaultValue) == 0 && (context.Attributes & BindableContextAttributes.IsSetFromStyle) == 0) { return; } context = context ?? GetOrCreateContext(targetProperty); if (fromStyle) { context.Attributes |= BindableContextAttributes.IsSetFromStyle; } else { context.Attributes &= ~BindableContextAttributes.IsSetFromStyle; } if (context.Binding != null) { context.Binding.Unapply(); } BindingBase oldBinding = context.Binding; context.Binding = binding; if (targetProperty.BindingChanging != null) { targetProperty.BindingChanging(this, oldBinding, binding); } binding.Apply(BindingContext, this, targetProperty); }
BindablePropertyContext GetOrCreateContext(BindableProperty property) { BindablePropertyContext context = GetContext(property); if (context == null) { context = CreateAndAddContext(property); } else if (property.ValueGetter != null) { context.Value = property.ValueGetter(this); //Update Value from dali }//added by xiaohui.fang else if (property.DefaultValueCreator != null) //This will be removed in the future. { context.Value = property.DefaultValueCreator(this); //Update Value from dali }//added by xb.teng return(context); }
public void EnforceNotifyBindedInstance(BindableProperty property) { if (null != property) { BindablePropertyContext context = GetOrCreateContext(property); BindingBase binding = context.Binding; var currentlyApplying = applying; if (binding != null && !currentlyApplying) { applying = true; binding.Apply(true); applying = false; } OnPropertyChanged(property.PropertyName); PropertyToGroup.TryGetValue(property, out HashSet <BindableProperty> propertyGroup); if (null != propertyGroup) { foreach (var relativeProperty in propertyGroup) { if (relativeProperty != property) { var relativeContext = GetOrCreateContext(relativeProperty); var relativeBinding = relativeContext.Binding; if (null != relativeBinding) { applying = true; relativeBinding.Apply(true); applying = false; } OnPropertyChanged(relativeProperty.PropertyName); } } } } }
internal void ApplyBindings(bool skipBindingContext, bool fromBindingContextChanged) { for (int i = 0, propLength = _properties.Count; i < propLength; i++) { BindablePropertyContext context = _properties [i]; BindingBase binding = context.Binding; if (binding == null) { continue; } if (skipBindingContext && ReferenceEquals(context.Property, BindingContextProperty)) { continue; } binding.Unapply(fromBindingContextChanged: fromBindingContextChanged); binding.Apply(BindingContext, this, context.Property, fromBindingContextChanged: fromBindingContextChanged); } }
void ApplyBindings(bool skipBindingContext) { var prop = _properties.ToArray(); for (int i = 0, propLength = prop.Length; i < propLength; i++) { BindablePropertyContext context = prop [i]; BindingBase binding = context.Binding; if (binding == null) { continue; } if (skipBindingContext && ReferenceEquals(context.Property, BindingContextProperty)) { continue; } binding.Unapply(); binding.Apply(BindingContext, this, context.Property); } }
public static void SetInheritedBindingContext(BindableObject bindable, object value) { if (null == bindable) { throw new ArgumentNullException(nameof(bindable)); } BindablePropertyContext bpContext = bindable.GetContext(BindingContextProperty); if (bpContext != null && ((bpContext.Attributes & BindableContextAttributes.IsManuallySet) != 0)) { return; } object oldContext = bindable.inheritedContext; if (ReferenceEquals(oldContext, value)) { return; } if (bpContext != null && oldContext == null) { oldContext = bpContext.Value; } if (bpContext != null && bpContext.Binding != null) { bpContext.Binding.Context = value; bindable.inheritedContext = null; } else { bindable.inheritedContext = value; } bindable.ApplyBindings(skipBindingContext: false, fromBindingContextChanged: true); bindable.OnBindingContextChanged(); }
void SetValue(BindableProperty property, object value, bool fromStyle, bool checkAccess) { if (property == null) { throw new ArgumentNullException("property"); } if (checkAccess && property.IsReadOnly) { throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName)); } BindablePropertyContext context = null; if (fromStyle && (context = GetContext(property)) != null && (context.Attributes & BindableContextAttributes.IsDefaultValue) == 0 && (context.Attributes & BindableContextAttributes.IsSetFromStyle) == 0) { return; } SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource, (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0)); }
internal void InternalSetValue(BindableProperty property, object value) { if (true == IsBinded) { SetValue(property, value, false, true); } else { if (null == property) { throw new ArgumentNullException(nameof(property)); } object oldvalue = null; if (null == property.DefaultValueCreator) { BindablePropertyContext context = GetOrCreateContext(property); if (null != context) { context.Attributes |= BindableContextAttributes.IsManuallySet; oldvalue = context.Value; context.Value = value; } } else { oldvalue = property.DefaultValueCreator.Invoke(this); } property.PropertyChanged?.Invoke(this, oldvalue, value); OnPropertyChanged(property.PropertyName); OnPropertyChangedWithData(property); } ChangedPropertiesSet.Add(property); }
internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal) { bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0; bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0; bool silent = (privateAttributes & SetValuePrivateFlags.Silent) != 0; bool fromStyle = (privateAttributes & SetValuePrivateFlags.FromStyle) != 0; bool converted = (privateAttributes & SetValuePrivateFlags.Converted) != 0; if (property == null) { throw new ArgumentNullException(nameof(property)); } if (checkAccess && property.IsReadOnly) { Debug.WriteLine("Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName); return; } if (!converted && !property.TryConvert(ref value)) { Console.WriteLine("SetValue", "Can not convert {0} to type '{1}'", value, property.ReturnType); return; } if (property.ValidateValue != null && !property.ValidateValue(this, value)) { throw new ArgumentException("Value was an invalid value for " + property.PropertyName, nameof(value)); } if (property.CoerceValue != null) { value = property.CoerceValue(this, value); } BindablePropertyContext context = GetOrCreateContext(property); if (manuallySet) { context.Attributes |= BindableContextAttributes.IsManuallySet; context.Attributes &= ~BindableContextAttributes.IsSetFromStyle; } else { context.Attributes &= ~BindableContextAttributes.IsManuallySet; } if (fromStyle) { context.Attributes |= BindableContextAttributes.IsSetFromStyle; } // else omitted on purpose bool currentlyApplying = _applying; if ((context.Attributes & BindableContextAttributes.IsBeingSet) != 0) { Queue <SetValueArgs> delayQueue = context.DelayedSetters; if (delayQueue == null) { context.DelayedSetters = delayQueue = new Queue <SetValueArgs>(); } delayQueue.Enqueue(new SetValueArgs(property, context, value, currentlyApplying, attributes)); } else { context.Attributes |= BindableContextAttributes.IsBeingSet; SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent); Queue <SetValueArgs> delayQueue = context.DelayedSetters; if (delayQueue != null) { while (delayQueue.Count > 0) { SetValueArgs s = delayQueue.Dequeue(); SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes); } context.DelayedSetters = null; } context.Attributes &= ~BindableContextAttributes.IsBeingSet; } }
void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false) { object original = context.Value; bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0; bool clearDynamicResources = (attributes & SetValueFlags.ClearDynamicResource) != 0; bool clearOneWayBindings = (attributes & SetValueFlags.ClearOneWayBindings) != 0; bool clearTwoWayBindings = (attributes & SetValueFlags.ClearTwoWayBindings) != 0; bool same = ReferenceEquals(context.Property, BindingContextProperty) ? ReferenceEquals(value, original) : Equals(value, original); if (!silent && (!same || raiseOnEqual)) { property.PropertyChanging?.Invoke(this, original, value); OnPropertyChanging(property.PropertyName); } if (!same || raiseOnEqual) { context.Value = value; } context.Attributes &= ~BindableContextAttributes.IsDefaultValue; context.Attributes &= ~BindableContextAttributes.IsDefaultValueCreated; if ((context.Attributes & BindableContextAttributes.IsDynamicResource) != 0 && clearDynamicResources) { RemoveDynamicResource(property); } BindingBase binding = context.Binding; if (binding != null) { if (clearOneWayBindings && binding.GetRealizedMode(property) == BindingMode.OneWay || clearTwoWayBindings && binding.GetRealizedMode(property) == BindingMode.TwoWay) { RemoveBinding(property, context); binding = null; } } PropertyToGroup.TryGetValue(property, out HashSet <BindableProperty> propertyGroup); if (!silent) { if ((!same || raiseOnEqual)) { property.PropertyChanged?.Invoke(this, original, value); if (binding != null && !currentlyApplying) { applying = true; binding.Apply(true); applying = false; } OnPropertyChanged(property.PropertyName); if (null != propertyGroup) { foreach (var relativeProperty in propertyGroup) { if (relativeProperty != property) { var relativeContext = GetOrCreateContext(relativeProperty); var relativeBinding = relativeContext.Binding; if (null != relativeBinding) { applying = true; relativeBinding.Apply(true); applying = false; } OnPropertyChanged(relativeProperty.PropertyName); } } } } else if (true == same && true == forceSendChangeSignal) { if (binding != null && !currentlyApplying) { applying = true; binding.Apply(true); applying = false; } OnPropertyChanged(property.PropertyName); if (null != propertyGroup) { foreach (var relativeProperty in propertyGroup) { if (relativeProperty != property) { var relativeContext = GetOrCreateContext(relativeProperty); var relativeBinding = relativeContext.Binding; if (null != relativeBinding) { applying = true; relativeBinding.Apply(true); applying = false; } OnPropertyChanged(relativeProperty.PropertyName); } } } } OnPropertyChangedWithData(property); } }