Beispiel #1
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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;
                }
            }

            PropertyToGroup.TryGetValue(property, out HashSet <BindableProperty> propertyGroup);

            if (!silent && (!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);
                        }
                    }
                }

                OnPropertyChangedWithData(property);
            }
        }