//------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------


        // Create a BindingExpression for position i
        BindingExpressionBase AttachBindingExpression(int i, bool replaceExisting)
        {
            DependencyObject target = TargetElement;

            if (target == null)
            {
                return(null);
            }

            BindingBase binding = ParentPriorityBinding.Bindings[i];

            BindingExpressionBase bindExpr = binding.CreateBindingExpression(target, TargetProperty, this);

            if (replaceExisting) // replace exisiting or add as new binding?
            {
                MutableBindingExpressions[i] = bindExpr;
            }
            else
            {
                MutableBindingExpressions.Add(bindExpr);
            }

            bindExpr.Attach(target, TargetProperty);
            return(bindExpr);
        }
        //----------------------------------------------------- 
        // 
        //  Public Methods
        // 
        //-----------------------------------------------------

        /// <summary>
        /// Attach a BindingExpression to a property. 
        /// </summary>
        /// <remarks> 
        /// A new BindingExpression is created from the given description, and attached to 
        /// the given property of the given object.  This method is the way to
        /// attach a Binding to an arbitrary DependencyObject that may not expose 
        /// its own SetBinding method.
        /// </remarks>
        /// <param name="target">object on which to attach the Binding</param>
        /// <param name="dp">property to which to attach the Binding</param> 
        /// <param name="binding">description of the Binding</param>
        /// <exception cref="ArgumentNullException"> target and dp and binding cannot be null </exception> 
        public static BindingExpressionBase SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) 
        {
            if (target == null) 
                throw new ArgumentNullException("target");
            if (dp == null)
                throw new ArgumentNullException("dp");
            if (binding == null) 
                throw new ArgumentNullException("binding");
//            target.VerifyAccess(); 
 
            BindingExpressionBase bindExpr = binding.CreateBindingExpression(target, dp);
 
            //

            target.SetValue(dp, bindExpr);
 
            return bindExpr;
        } 
        /// <summary>Creates and associates a new instance of <see cref="T:System.Windows.Data.BindingExpressionBase" /> with the specified binding target property.</summary>
        /// <param name="target">The binding target of the binding.</param>
        /// <param name="dp">The target property of the binding.</param>
        /// <param name="binding">The <see cref="T:System.Windows.Data.BindingBase" /> object that describes the binding.</param>
        /// <returns>The instance of <see cref="T:System.Windows.Data.BindingExpressionBase" /> created for and associated with the specified property. The <see cref="T:System.Windows.Data.BindingExpressionBase" /> class is the base class of <see cref="T:System.Windows.Data.BindingExpression" />, <see cref="T:System.Windows.Data.MultiBindingExpression" />, and <see cref="T:System.Windows.Data.PriorityBindingExpression" />.</returns>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="target" /> parameter cannot be <see langword="null" />.</exception>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="dp" /> parameter cannot be <see langword="null" />.</exception>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="binding" /> parameter cannot be <see langword="null" />.</exception>
        // Token: 0x06001A2A RID: 6698 RVA: 0x0007D094 File Offset: 0x0007B294
        public static BindingExpressionBase SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            BindingExpressionBase bindingExpressionBase = binding.CreateBindingExpression(target, dp);

            target.SetValue(dp, bindingExpressionBase);
            return(bindingExpressionBase);
        }
        // Token: 0x06001C85 RID: 7301 RVA: 0x00086094 File Offset: 0x00084294
        private BindingExpressionBase AttachBindingExpression(int i, bool replaceExisting)
        {
            DependencyObject targetElement = base.TargetElement;

            if (targetElement == null)
            {
                return(null);
            }
            BindingBase           bindingBase           = this.ParentPriorityBinding.Bindings[i];
            BindingExpressionBase bindingExpressionBase = bindingBase.CreateBindingExpression(targetElement, base.TargetProperty, this);

            if (replaceExisting)
            {
                this.MutableBindingExpressions[i] = bindingExpressionBase;
            }
            else
            {
                this.MutableBindingExpressions.Add(bindingExpressionBase);
            }
            bindingExpressionBase.Attach(targetElement, base.TargetProperty);
            return(bindingExpressionBase);
        }
Beispiel #5
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        /// <summary>
        /// Attach a BindingExpression to a property.
        /// </summary>
        /// <remarks>
        /// A new BindingExpression is created from the given description, and attached to
        /// the given property of the given object.  This method is the way to
        /// attach a Binding to an arbitrary DependencyObject that may not expose
        /// its own SetBinding method.
        /// </remarks>
        /// <param name="target">object on which to attach the Binding</param>
        /// <param name="dp">property to which to attach the Binding</param>
        /// <param name="binding">description of the Binding</param>
        /// <exception cref="ArgumentNullException"> target and dp and binding cannot be null </exception>
        public static BindingExpressionBase SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
//            target.VerifyAccess();

            BindingExpressionBase bindExpr = binding.CreateBindingExpression(target, dp);

            // BUG: should prevent transfers and updates until BindingExpression is ready
            //BindingExpression.SetFlag(BindingFlags.iInTransfer | BindingFlags.iInUpdate);
            target.SetValue(dp, bindExpr);

            return(bindExpr);
        }
        //-----------------------------------------------------
        //
        //  API for BindingExpressions with no target DP (task 20769) 
        //  This is internal for now, until we review whether we wish to
        //  make it public 
        // 
        //------------------------------------------------------
 
        /// <summary> Create an untargeted BindingExpression </summary>
        internal static BindingExpressionBase CreateUntargetedBindingExpression(DependencyObject d, BindingBase binding)
        {
            return binding.CreateBindingExpression(d, NoTargetProperty); 
        }