Example #1
0
 /// <summary>
 /// Assigns a binding to a property.
 /// </summary>
 /// <param name="targetProperty">The BindableProperty on which to set a binding.</param>
 /// <param name="binding">The binding to set.</param>
 public void SetBinding(BindableProperty targetProperty, BindingBase binding)
 {
     SetBinding(targetProperty, binding, false);
 }
Example #2
0
        static void BindingContextPropertyBindingChanging(BindableObject bindable, BindingBase oldBindingBase, BindingBase newBindingBase)
        {
            object context    = bindable._inheritedContext;
            var    oldBinding = oldBindingBase as Binding;
            var    newBinding = newBindingBase as Binding;

            if (context == null && oldBinding != null)
            {
                context = oldBinding.Context;
            }
            if (context != null && newBinding != null)
            {
                newBinding.Context = context;
            }
        }
Example #3
0
        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;
                }
            }

            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);
                }
                else if (true == same && true == forceSendChangeSignal)
                {
                    if (binding != null && !currentlyApplying)
                    {
                        _applying = true;
                        binding.Apply(true);
                        _applying = false;
                    }

                    OnPropertyChanged(property.PropertyName);
                }
            }
        }