예제 #1
0
        /// <summary>
        /// Will ensure events aren't triggered when value is set
        /// </summary>
        /// <param name="propertyPath"></param>
        /// <param name="value"></param>
        internal void SetValue(string[] propertyPath, object value, BindingRegistration bindingRegistrationToSkipNotifying, PropertyInfoAndObject preObtainedSourceProperty = null)
        {
            var property = preObtainedSourceProperty ?? GetProperty(propertyPath);

            if (property != null)
            {
                BindingHost bindingHost = null;
                InternalBindingRegistration internalRegistrationToSkip = null;
                if (bindingRegistrationToSkipNotifying != null)
                {
                    internalRegistrationToSkip = bindingRegistrationToSkipNotifying.GetFinalInternalRegistration();
                    bindingHost = FindBindingHost(propertyPath);
                    if (bindingHost != null)
                    {
                        bindingHost._bindingRegistrationToSkipOnce = internalRegistrationToSkip;
                    }
                }

                try
                {
                    property.PropertyInfo.SetValue(property.Object, value);
                }
                finally
                {
                    if (bindingHost != null && bindingHost._bindingRegistrationToSkipOnce == internalRegistrationToSkip)
                    {
                        bindingHost._bindingRegistrationToSkipOnce = null;
                    }
                }
            }
        }
예제 #2
0
 internal BindingRegistration(BindingHost host, string propertyName, BindingRegistration subRegistration, string[] fullPropertyPath)
 {
     BindingHost       = host;
     PropertyName      = propertyName;
     SubRegistration   = subRegistration;
     _fullPropertyPath = fullPropertyPath;
 }
예제 #3
0
        private BindingRegistration SetBinding(string[] propertyPaths, Action action, bool skipInvokingActionImmediately, bool topLevel = true)
        {
            string immediatePath = propertyPaths[0];

            if (propertyPaths.Length == 1)
            {
                List <InternalBindingRegistration> storedBindings;
                if (!_bindings.TryGetValue(immediatePath, out storedBindings))
                {
                    storedBindings           = new List <InternalBindingRegistration>();
                    _bindings[immediatePath] = storedBindings;
                }

                var internalRegistration = new InternalBindingRegistration(action);
                storedBindings.Add(internalRegistration);

                // We require DataContext to be set here since bindings can be wired before DataContext is set
                if (DataContext != null && !skipInvokingActionImmediately)
                {
                    action();
                }

                return(new BindingRegistration(this, immediatePath, internalRegistration, topLevel ? propertyPaths : null));
            }
            else
            {
                BindingHost subBinding;
                if (!_subPropertyBindings.TryGetValue(immediatePath, out subBinding))
                {
                    subBinding = new BindingHost()
                    {
                        DataContext = GetValueFromSingleProperty(propertyPaths[0])
                    };
                    _subPropertyBindings[immediatePath] = subBinding;
                }

                var subRegistration = subBinding.SetBinding(propertyPaths.Skip(1).ToArray(), action, skipInvokingActionImmediately, topLevel: false);

                // For this we need to execute first time even if data context was null (for example binding Class.Name should execute even if Class was null)
                if (DataContext != null && subBinding.DataContext == null && !skipInvokingActionImmediately)
                {
                    action();
                }

                return(new BindingRegistration(this, immediatePath, subRegistration, topLevel ? propertyPaths : null));
            }
        }
예제 #4
0
 public PropertyInfoAndObject GetSourceProperty()
 {
     return(BindingHost.GetProperty(_fullPropertyPath));
 }
예제 #5
0
 /// <summary>
 /// Will ensure this binding registration's callback isn't triggered when value is set
 /// </summary>
 /// <param name="propertyPath"></param>
 /// <param name="value"></param>
 public void SetSourceValue(object value, PropertyInfoAndObject preObtainedSourceProperty = null)
 {
     BindingHost.SetValue(_fullPropertyPath, value, IsEmptyRegistration ? null : this, preObtainedSourceProperty: preObtainedSourceProperty);
 }
예제 #6
0
 public void Unregister()
 {
     BindingHost.UnregisterBinding(this);
 }