Exemplo n.º 1
0
        void ReplaceDependencySources()
        {
            if (!ParentBindingExpression.IsDetaching)
            {
                int size = PW.Length;
                if (PW.NeedsDirectNotification)
                {
                    ++size;
                }

                WeakDependencySource[] newSources = new WeakDependencySource[size];
                int n = 0;

                if (IsDynamic)
                {
                    for (int k = 0; k < PW.Length; ++k)
                    {
                        DependencyProperty dp = PW.GetAccessor(k) as DependencyProperty;
                        if (dp != null)
                        {
                            DependencyObject d = PW.GetItem(k) as DependencyObject;
                            if (d != null)
                            {
                                newSources[n++] = new WeakDependencySource(d, dp);
                            }
                        }
                    }

                    if (PW.NeedsDirectNotification)
                    {
                        // subproperty notifications can only arise from Freezables
                        // (as of today - 11/14/08), so we only need to propagate
                        // them when the raw value is a Freezable.
                        DependencyObject d = PW.RawValue() as Freezable;
                        if (d != null)
                        {
                            newSources[n++] = new WeakDependencySource(d, DependencyObject.DirectDependencyProperty);
                        }
                    }
                }

                ParentBindingExpression.ChangeWorkerSources(newSources, n);
            }
        }
Exemplo n.º 2
0
        internal override void UpdateValue(object value)
        {
            int    k    = PW.Length - 1;
            object item = PW.GetItem(k);

            if (item == null || item == BindingExpression.NullDataItem)
            {
                return;
            }

            // if the binding is async, post a request to set the value
            if (ParentBinding.IsAsync && !(PW.GetAccessor(k) is DependencyProperty))
            {
                RequestAsyncSetValue(item, value);
                return;
            }

            PW.SetValue(item, value);
        }
Exemplo n.º 3
0
        void RequestAsyncSetValue(object item, object value)
        {
            // get information about the property whose value we want
            string name = GetNameFromInfo(PW.GetAccessor(PW.Length - 1));

            Invariant.Assert(name != null, "Async SetValue expects a name");

            // abandon any previous request
            AsyncSetValueRequest pendingSetValueRequest = (AsyncSetValueRequest)GetValue(Feature.PendingSetValueRequest, null);

            if (pendingSetValueRequest != null)
            {
                pendingSetValueRequest.Cancel();
            }

            // issue the new request
            pendingSetValueRequest =
                new AsyncSetValueRequest(item, name, value, ParentBinding.AsyncState,
                                         DoSetValueCallback, CompleteSetValueCallback,
                                         this);
            SetValue(Feature.PendingSetValueRequest, pendingSetValueRequest);
            Engine.AddAsyncRequest(TargetElement, pendingSetValueRequest);
        }