Пример #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);
            }
        }
Пример #2
0
 // Token: 0x0600748C RID: 29836 RVA: 0x002158A8 File Offset: 0x00213AA8
 private void ReplaceDependencySources()
 {
     if (!base.ParentBindingExpression.IsDetaching)
     {
         int num = this.PW.Length;
         if (this.PW.NeedsDirectNotification)
         {
             num++;
         }
         WeakDependencySource[] array = new WeakDependencySource[num];
         int n = 0;
         if (base.IsDynamic)
         {
             for (int i = 0; i < this.PW.Length; i++)
             {
                 DependencyProperty dependencyProperty = this.PW.GetAccessor(i) as DependencyProperty;
                 if (dependencyProperty != null)
                 {
                     DependencyObject dependencyObject = this.PW.GetItem(i) as DependencyObject;
                     if (dependencyObject != null)
                     {
                         array[n++] = new WeakDependencySource(dependencyObject, dependencyProperty);
                     }
                 }
             }
             if (this.PW.NeedsDirectNotification)
             {
                 DependencyObject dependencyObject2 = this.PW.RawValue() as Freezable;
                 if (dependencyObject2 != null)
                 {
                     array[n++] = new WeakDependencySource(dependencyObject2, DependencyObject.DirectDependencyProperty);
                 }
             }
         }
         base.ParentBindingExpression.ChangeWorkerSources(array, n);
     }
 }
 /// <summary>
 /// Change the dependency sources for the given child expression.
 /// </summary>
 internal override void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources)
 {
     // BindingExpression does not support child bindings
 }
        // worker calls here if it changes its dependency sources
        // n is the number of real entries in newWorkerSources (which may be longer)
        internal void ChangeWorkerSources(WeakDependencySource[] newWorkerSources, int n)
        {
            int offset = 0;
            int size = n;

            // create the new sources array, and add the context and CollectionViewSource elements
            DependencyObject contextElement = ContextElement;
            CollectionViewSource cvs = CollectionViewSource;
            bool usesLanguage = UsesLanguage;

            if (contextElement != null)
                ++size;
            if (cvs != null)
                ++size;
            if (usesLanguage)
                ++size;

            WeakDependencySource[] newSources = (size > 0) ? new WeakDependencySource[size] : null;

            if (contextElement != null)
            {
                newSources[offset++] = new WeakDependencySource(_ctxElement, FrameworkElement.DataContextProperty);
            }

            if (cvs != null)
            {
                WeakReference wr = GetValue(Feature.CollectionViewSource, null) as WeakReference;
                newSources[offset++] =
                    (wr != null) ? new WeakDependencySource(wr, CollectionViewSource.ViewProperty)
                                 : new WeakDependencySource(cvs, CollectionViewSource.ViewProperty);
            }

            if (usesLanguage)
            {
                newSources[offset++] = new WeakDependencySource(TargetElementReference, FrameworkElement.LanguageProperty);
            }

            // add the worker's sources
            if (n > 0)
                Array.Copy(newWorkerSources, 0, newSources, offset, n);

            // tell the property engine
            ChangeSources(newSources);
        }
Пример #5
0
 /// <summary> 
 /// Change the dependency sources for the given child expression.
 /// </summary>
 internal abstract void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources);
Пример #6
0
        /// <summary>
        /// combine the sources of BindingExpressions, using new sources for 
        /// the BindingExpression at the given index
        /// </summary>
        /// <param name="index">-1 to indicate no new sources</param>
        /// <param name="bindingExpressions">collection of child binding expressions </param> 
        /// <param name="count">how many child expressions to include</param>
        /// <param name="newSources">use null when no new sources</param> 
        /// <returns></returns> 
        internal static WeakDependencySource[] CombineSources(int index, Collection<BindingExpressionBase> bindingExpressions, int count, WeakDependencySource[] newSources)
        { 
            if (index == count)
            {
                // Be sure to include newSources if they are being appended
                count++; 
            }
 
            Collection<WeakDependencySource> tempList = new Collection<WeakDependencySource>(); 

            for (int i = 0; i < count; ++i) 
            {
                BindingExpressionBase bindExpr = bindingExpressions[i];
                WeakDependencySource[] sources = (i==index) ? newSources :
                                            (bindExpr != null) ? bindExpr.WeakSources : 
                                            null;
                int m = (sources == null) ? 0 : sources.Length; 
                for (int j = 0; j < m; ++j) 
                {
                    WeakDependencySource candidate = sources[j]; 

                    // don't add duplicate source
                    for (int k = 0; k < tempList.Count; ++k)
                    { 
                        WeakDependencySource prior = tempList[k];
                        if (candidate.DependencyObject == prior.DependencyObject && 
                            candidate.DependencyProperty == prior.DependencyProperty) 
                        {
                            candidate = null; 
                            break;
                        }
                    }
 
                    if (candidate != null)
                        tempList.Add(candidate); 
                } 
            }
 
            WeakDependencySource[] result;
            if (tempList.Count > 0)
            {
                result = new WeakDependencySource[tempList.Count]; 
                tempList.CopyTo(result, 0);
                tempList.Clear(); 
            } 
            else
            { 
                result = null;
            }

            return result; 
        }
Пример #7
0
        // change WeakDependencySources to (strong) DependencySources, and notify 
        // the property engine about the new sources 
        void ChangeSources(DependencyObject target, DependencyProperty dp, WeakDependencySource[] newSources)
        { 
            DependencySource[] sources;

            if (newSources != null)
            { 
                // convert weak reference to strong
                sources = new DependencySource[newSources.Length]; 
                int n = 0; 
                for (int i = 0; i < newSources.Length; ++i)
                { 
                    DependencyObject sourceDO = newSources[i].DependencyObject;
                    if (sourceDO != null)
                    {
                        // only include sources that are still alive 
                        sources[n++] = new DependencySource(sourceDO, newSources[i].DependencyProperty);
                    } 
                } 

                // if any of the sources were no longer alive, trim the array 
                if (n < newSources.Length)
                {
                    DependencySource[] temp;
                    if (n > 0) 
                    {
                        temp = new DependencySource[n]; 
                        Array.Copy(sources, 0, temp, 0, n); 
                    }
                    else 
                    {
                        temp = null;
                    }
 
                    sources = temp;
                } 
            } 
            else
            { 
                sources = null;
            }

            // notify property engine 
            ChangeSources(target, dp, sources);
        } 
Пример #8
0
        internal void ChangeSources(WeakDependencySource[] newSources) 
        { 
            if (IsInBindingExpressionCollection)
                ParentBindingExpressionBase.ChangeSourcesForChild(this, newSources); 
            else
                ChangeSources(TargetElement, TargetProperty, newSources);

            // store the sources with weak refs, so they don't cause memory leaks (bug 980041) 
            _sources = newSources;
        } 
Пример #9
0
    /// <summary>
    /// Change the dependency sources for the given child expression.
    /// </summary>
    internal override void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources)
    {
        int index = MutableBindingExpressions.IndexOf(bindingExpression);

        if (index >= 0)
        {
            WeakDependencySource[] combinedSources = CombineSources(index, MutableBindingExpressions, AttentiveBindingExpressions, newSources);
            ChangeSources(combinedSources);
        }
    }
Пример #10
0
    /// <summary>
    /// Change the dependency sources for the given child expression.
    /// </summary>
    internal override void ChangeSourcesForChild(BindingExpressionBase bindingExpression, WeakDependencySource[] newSources)
    {
        int index = MutableBindingExpressions.IndexOf(bindingExpression);

        if (index >= 0)
        {
            WeakDependencySource[] commonSources = null;
            if (UsesLanguage)
            {
                commonSources = new WeakDependencySource[] { new WeakDependencySource(TargetElement, FrameworkElement.LanguageProperty) };
            }

            WeakDependencySource[] combinedSources = CombineSources(index, MutableBindingExpressions, MutableBindingExpressions.Count, newSources, commonSources);
            ChangeSources(combinedSources);
        }
    }
Пример #11
0
    // Attach to things that may require tree context (parent, root, etc.)
    void AttachToContext(bool lastChance)
    {
        DependencyObject target = TargetElement;
        if (target == null)
            return;

        Debug.Assert(ParentMultiBinding.Converter != null || !String.IsNullOrEmpty(EffectiveStringFormat),
                "MultiBindingExpression should not exist if its bind does not have a valid converter.");

        bool isExtendedTraceEnabled = TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.AttachToContext);

        _converter = ParentMultiBinding.Converter;
        if (_converter == null && String.IsNullOrEmpty(EffectiveStringFormat))
        {
            TraceData.Trace(TraceEventType.Error, TraceData.MultiBindingHasNoConverter, ParentMultiBinding);
        }

        if (isExtendedTraceEnabled)
        {
            TraceData.Trace(TraceEventType.Warning,
                                TraceData.AttachToContext(
                                    TraceData.Identify(this),
                                    lastChance ? " (last chance)" : String.Empty));
        }

        TransferIsDeferred = true;
        bool attached = true;       // true if all child bindings have attached
        int count = MutableBindingExpressions.Count;
        for (int i = 0; i < count; ++i)
        {
            if (MutableBindingExpressions[i].StatusInternal == BindingStatusInternal.Unattached)
                attached = false;
        }

        // if the child bindings aren't ready yet, try again later.  Leave
        // TransferIsDeferred set, to indicate we're not ready yet.
        if (!attached && !lastChance)
        {
            if (isExtendedTraceEnabled)
            {
                TraceData.Trace(TraceEventType.Warning,
                                    TraceData.ChildNotAttached(
                                        TraceData.Identify(this)));
            }

            return;
        }

        // listen to the Language property, if needed
        if (UsesLanguage)
        {
            WeakDependencySource[] commonSources = new WeakDependencySource[] { new WeakDependencySource(TargetElement, FrameworkElement.LanguageProperty) };
            WeakDependencySource[] newSources = CombineSources(-1, MutableBindingExpressions, MutableBindingExpressions.Count, null, commonSources);
            ChangeSources(newSources);
        }

        // initial transfer
        bool initialTransferIsUpdate = IsOneWayToSource;
        object currentValue;
        if (ShouldUpdateWithCurrentValue(target, out currentValue))
        {
            initialTransferIsUpdate = true;
            ChangeValue(currentValue, /*notify*/false);
            NeedsUpdate = true;
        }

        SetStatus(BindingStatusInternal.Active);

        if (!initialTransferIsUpdate)
        {
            UpdateTarget(false);
        }
        else
        {
            UpdateValue();
        }
    }
Пример #12
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); 
            }
        }