Exemplo n.º 1
0
        // Token: 0x06000C65 RID: 3173 RVA: 0x0002E3C0 File Offset: 0x0002C5C0
        internal static FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ref ChildRecord childRecord, bool isChildRecordValid, bool hasStyleChanged, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            DependencyObject dependencyObject = (fe != null) ? fe : fce;
            FrameworkObject  frameworkObject  = new FrameworkObject(fe, fce);
            FrugalObjectList <DependencyProperty> frugalObjectList = info.InheritablePropertiesStack.Peek();
            int num = (frugalObjectList != null) ? frugalObjectList.Count : 0;
            FrugalObjectList <DependencyProperty> frugalObjectList2 = null;

            if (TreeWalkHelper.HasChildren(fe, fce))
            {
                frugalObjectList2 = new FrugalObjectList <DependencyProperty>(num);
            }
            info.ResetInheritableValueIndexer();
            for (int i = 0; i < num; i++)
            {
                DependencyProperty dependencyProperty = frugalObjectList[i];
                PropertyMetadata   metadata           = dependencyProperty.GetMetadata(dependencyObject);
                if (metadata.IsInherited)
                {
                    FrameworkPropertyMetadata frameworkPropertyMetadata = (FrameworkPropertyMetadata)metadata;
                    bool flag = TreeWalkHelper.InvalidateTreeDependentProperty(info, dependencyObject, ref frameworkObject, dependencyProperty, frameworkPropertyMetadata, selfStyle, selfThemeStyle, ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent);
                    if (flag && frugalObjectList2 != null && (!TreeWalkHelper.SkipNow(frameworkObject.InheritanceBehavior) || frameworkPropertyMetadata.OverridesInheritanceBehavior))
                    {
                        frugalObjectList2.Add(dependencyProperty);
                    }
                }
            }
            return(frugalObjectList2);
        }
Exemplo n.º 2
0
        // Token: 0x06000C62 RID: 3170 RVA: 0x0002E35C File Offset: 0x0002C55C
        private static bool OnAncestorChanged(DependencyObject d, TreeChangeInfo info, bool visitedViaVisualTree)
        {
            FrameworkObject frameworkObject = new FrameworkObject(d, true);

            TreeWalkHelper.OnAncestorChanged(frameworkObject.FE, frameworkObject.FCE, info);
            return(true);
        }
Exemplo n.º 3
0
        // disconnect from an old mentor
        void DisconnectMentor(DependencyObject mentor)
        {
            FrameworkObject foMentor = new FrameworkObject(mentor);

            // unregister for InheritedPropertyChanged events
            foMentor.InheritedPropertyChanged -= new InheritedPropertyChangedEventHandler(OnMentorInheritedPropertyChanged);

            // unregister for ResourcesChanged events
            foMentor.ResourcesChanged -= new EventHandler(OnMentorResourcesChanged);

            // invalidate the mentee's tree
            TreeWalkHelper.InvalidateOnTreeChange(
                this, null,

                foMentor.DO,
                false     /* isAddOperation */
                );

            // unregister for Loaded/Unloaded events
            if (this.SubtreeHasLoadedChangeHandler)
            {
                bool isLoaded = foMentor.IsLoaded;

                DisconnectLoadedEvents(ref foMentor, isLoaded);

                if (foMentor.IsLoaded)
                {
                    this.FireUnloadedOnDescendentsInternal();
                }
            }
        }
Exemplo n.º 4
0
        // connect to a new mentor
        void ConnectMentor(DependencyObject mentor)
        {
            FrameworkObject foMentor = new FrameworkObject(mentor);

            // register for InheritedPropertyChanged events
            foMentor.InheritedPropertyChanged += new InheritedPropertyChangedEventHandler(OnMentorInheritedPropertyChanged);

            // register for ResourcesChanged events
            foMentor.ResourcesChanged += new EventHandler(OnMentorResourcesChanged);

            // invalidate the mentee's tree
            TreeWalkHelper.InvalidateOnTreeChange(
                this, null,

                foMentor.DO,
                true     /* isAddOperation */
                );

            // register for Loaded/Unloaded events.
            // Do this last so the tree is ready when Loaded is raised.
            if (this.SubtreeHasLoadedChangeHandler)
            {
                bool isLoaded = foMentor.IsLoaded;

                ConnectLoadedEvents(ref foMentor, isLoaded);

                if (isLoaded)
                {
                    this.FireLoadedOnDescendentsInternal();
                }
            }
        }
Exemplo n.º 5
0
        // handle the InheritedPropertyChanged event from the mentor
        void OnMentorInheritedPropertyChanged(object sender, InheritedPropertyChangedEventArgs e)
        {
            TreeWalkHelper.InvalidateOnInheritablePropertyChange(
                this, null,

                e.Info, false /*skipStartNode*/);
        }
Exemplo n.º 6
0
        // handle the ResourcesChanged event from the mentor
        void OnMentorResourcesChanged(object sender, EventArgs e)
        {
            TreeWalkHelper.InvalidateOnResourcesChange(
                this, null,

                ResourcesChangeInfo.CatastrophicDictionaryChangeInfo);
        }
Exemplo n.º 7
0
 // Token: 0x06000C6E RID: 3182 RVA: 0x0002ECD4 File Offset: 0x0002CED4
 internal static void OnInheritedPropertyChanged(DependencyObject d, ref InheritablePropertyChangeInfo info, InheritanceBehavior inheritanceBehavior)
 {
     if (inheritanceBehavior == InheritanceBehavior.Default || TreeWalkHelper.IsForceInheritedProperty(info.Property))
     {
         FrameworkObject frameworkObject = new FrameworkObject(d);
         frameworkObject.OnInheritedPropertyChanged(ref info);
     }
 }
Exemplo n.º 8
0
        internal void OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
        {
            // Cache the IsSelfInheritanceParent flag
            bool wasSelfInheritanceParent = IsSelfInheritanceParent;

            if (parentTreeState.Root != this)
            {
                // Clear the HasStyleChanged flag
                HasStyleChanged     = false;
                HasStyleInvalidated = false;
            }

            // If this is a tree add operation update the ShouldLookupImplicitStyles
            // flag with respect to your parent.
            if (parentTreeState.IsAddOperation)
            {
                FrameworkObject fo =

                    new FrameworkObject(null, this);
                fo.SetShouldLookupImplicitStyles();
            }

            // Invalidate ResourceReference properties
            if (HasResourceReference)
            {
                // This operation may cause a style change and hence should be done before the call to
                // InvalidateTreeDependents as it relies on the HasStyleChanged flag
                TreeWalkHelper.OnResourcesChanged(this, ResourcesChangeInfo.TreeChangeInfo, false);
            }

            // If parent is a FrameworkElement
            // This is also an operation that could change the style
            FrugalObjectList <DependencyProperty> currentInheritableProperties =
                InvalidateTreeDependentProperties(parentTreeState, IsSelfInheritanceParent, wasSelfInheritanceParent);

            // we have inherited properties that changes as a result of the above;
            // invalidation; push that list of inherited properties on the stack
            // for the children to use
            parentTreeState.InheritablePropertiesStack.Push(currentInheritableProperties);


            // Notify the PresentationSource that this element's ancestry may have changed.
            // We only need the ContentElement's because UIElements are taken care of
            // through the Visual class.
            PresentationSource.OnAncestorChanged(this);


            // Call OnAncestorChanged
            OnAncestorChanged();

            // Notify mentees if they exist
            if (PotentiallyHasMentees)
            {
                // Raise the ResourcesChanged Event so that ResourceReferenceExpressions
                // on non-[FE/FCE] listening for this can then update their values
                RaiseClrEvent(FrameworkElement.ResourcesChangedKey, EventArgs.Empty);
            }
        }
Exemplo n.º 9
0
 // Token: 0x06000C66 RID: 3174 RVA: 0x0002E490 File Offset: 0x0002C690
 private static bool InvalidateTreeDependentProperty(TreeChangeInfo info, DependencyObject d, ref FrameworkObject fo, DependencyProperty dp, FrameworkPropertyMetadata fMetadata, Style selfStyle, Style selfThemeStyle, ref ChildRecord childRecord, bool isChildRecordValid, bool hasStyleChanged, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
 {
     if (!TreeWalkHelper.SkipNext(fo.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior)
     {
         InheritablePropertyChangeInfo rootInheritableValue = info.GetRootInheritableValue(dp);
         EffectiveValueEntry           oldEntry             = rootInheritableValue.OldEntry;
         EffectiveValueEntry           effectiveValueEntry  = info.IsAddOperation ? rootInheritableValue.NewEntry : new EffectiveValueEntry(dp, BaseValueSourceInternal.Inherited);
         bool flag = TreeWalkHelper.IsForceInheritedProperty(dp);
         if (d != info.Root)
         {
             if (wasSelfInheritanceParent)
             {
                 oldEntry = d.GetValueEntry(d.LookupEntry(dp.GlobalIndex), dp, fMetadata, RequestFlags.DeferredReferences);
             }
             else if (isSelfInheritanceParent)
             {
                 EffectiveValueEntry valueEntry = d.GetValueEntry(d.LookupEntry(dp.GlobalIndex), dp, fMetadata, RequestFlags.DeferredReferences);
                 if (valueEntry.BaseValueSourceInternal <= BaseValueSourceInternal.Inherited)
                 {
                     oldEntry = oldEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                     oldEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
                 }
                 else
                 {
                     oldEntry = valueEntry;
                 }
             }
             else
             {
                 oldEntry = oldEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                 oldEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
             }
         }
         else if (info.IsAddOperation && (flag || oldEntry.BaseValueSourceInternal <= BaseValueSourceInternal.Inherited))
         {
             EffectiveValueEntry valueEntry2 = d.GetValueEntry(d.LookupEntry(dp.GlobalIndex), dp, fMetadata, RequestFlags.DeferredReferences);
             if (valueEntry2.BaseValueSourceInternal > BaseValueSourceInternal.Inherited)
             {
                 oldEntry = valueEntry2;
             }
         }
         OperationType operationType = info.IsAddOperation ? OperationType.AddChild : OperationType.RemoveChild;
         if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
         {
             return((d.UpdateEffectiveValue(d.LookupEntry(dp.GlobalIndex), dp, fMetadata, oldEntry, ref effectiveValueEntry, false, false, operationType) & (UpdateResult)5) == UpdateResult.ValueChanged);
         }
         if (flag)
         {
             effectiveValueEntry = new EffectiveValueEntry(dp, FullValueSource.IsCoerced);
             return((d.UpdateEffectiveValue(d.LookupEntry(dp.GlobalIndex), dp, fMetadata, oldEntry, ref effectiveValueEntry, false, false, operationType) & (UpdateResult)5) == UpdateResult.ValueChanged);
         }
     }
     return(false);
 }
Exemplo n.º 10
0
        /// <summary>
        ///     This method causes the ThemeStyleProperty to be re-evaluated
        /// </summary>
        internal void UpdateThemeStyleProperty()
        {
            if (IsThemeStyleUpdateInProgress == false)
            {
                IsThemeStyleUpdateInProgress = true;
                try
                {
                    StyleHelper.GetThemeStyle(/* fe = */ this, /* fce = */ null);

                    // Update the ContextMenu and ToolTips separately because they aren't in the tree
                    ContextMenu contextMenu =
                        GetValueEntry(
                            LookupEntry(ContextMenuProperty.GlobalIndex),
                            ContextMenuProperty,
                            null,
                            RequestFlags.DeferredReferences).Value as ContextMenu;
                    if (contextMenu != null)
                    {
                        TreeWalkHelper.InvalidateOnResourcesChange(contextMenu, null, ResourcesChangeInfo.ThemeChangeInfo);
                    }

                    DependencyObject toolTip =
                        GetValueEntry(
                            LookupEntry(ToolTipProperty.GlobalIndex),
                            ToolTipProperty,
                            null,
                            RequestFlags.DeferredReferences).Value as DependencyObject;

                    if (toolTip != null)
                    {
                        FrameworkObject toolTipFO = new FrameworkObject(toolTip);
                        if (toolTipFO.IsValid)
                        {
                            TreeWalkHelper.InvalidateOnResourcesChange(toolTipFO.FE, toolTipFO.FCE, ResourcesChangeInfo.ThemeChangeInfo);
                        }
                    }

                    OnThemeChanged();
                }
                finally
                {
                    IsThemeStyleUpdateInProgress = false;
                }
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.CyclicThemeStyleReferenceDetected, this));
            }
        }
Exemplo n.º 11
0
        // Token: 0x06000C67 RID: 3175 RVA: 0x0002E60C File Offset: 0x0002C80C
        internal static void InvalidateOnResourcesChange(FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info)
        {
            FrameworkObject frameworkObject = new FrameworkObject(fe, fce);

            frameworkObject.Reset(frameworkObject.TemplatedParent);
            frameworkObject.HasTemplateChanged = false;
            DependencyObject dependencyObject = (fe != null) ? fe : fce;

            if (TreeWalkHelper.HasChildren(fe, fce))
            {
                DescendentsWalker <ResourcesChangeInfo> descendentsWalker = new DescendentsWalker <ResourcesChangeInfo>(TreeWalkPriority.LogicalTree, TreeWalkHelper.ResourcesChangeDelegate, info);
                descendentsWalker.StartWalk(dependencyObject);
                return;
            }
            TreeWalkHelper.OnResourcesChanged(dependencyObject, info, true);
        }
Exemplo n.º 12
0
        // Token: 0x06000C6C RID: 3180 RVA: 0x0002EB1C File Offset: 0x0002CD1C
        internal static void InvalidateOnInheritablePropertyChange(FrameworkElement fe, FrameworkContentElement fce, InheritablePropertyChangeInfo info, bool skipStartNode)
        {
            DependencyProperty property        = info.Property;
            FrameworkObject    frameworkObject = new FrameworkObject(fe, fce);

            if (TreeWalkHelper.HasChildren(fe, fce))
            {
                DependencyObject @do = frameworkObject.DO;
                DescendentsWalker <InheritablePropertyChangeInfo> descendentsWalker = new DescendentsWalker <InheritablePropertyChangeInfo>(TreeWalkPriority.LogicalTree, TreeWalkHelper.InheritablePropertyChangeDelegate, info);
                descendentsWalker.StartWalk(@do, skipStartNode);
                return;
            }
            if (!skipStartNode)
            {
                bool visitedViaVisualTree = false;
                TreeWalkHelper.OnInheritablePropertyChanged(frameworkObject.DO, info, visitedViaVisualTree);
            }
        }
        //
        //  This method
        //  1. Is called from AncestorChange InvalidateTree.
        //  2. It is used to create the InheritableProperties on the given node.
        //  3. It also accumulates oldValues for the inheritable properties that are about to be invalidated
        //
        internal FrugalObjectList <DependencyProperty> CreateParentInheritableProperties(
            DependencyObject d,
            DependencyObject parent,
            bool isAddOperation)
        {
            Debug.Assert(d != null, "Must have non-null current node");

            if (parent == null)
            {
                return(new FrugalObjectList <DependencyProperty>(0));
            }

            DependencyObjectType treeObjDOT = d.DependencyObjectType;

            // See if we have a cached value.
            EffectiveValueEntry[] parentEffectiveValues = null;
            uint parentEffectiveValuesCount             = 0;
            uint inheritablePropertiesCount             = 0;

            // If inheritable properties aren't cached on you then use the effective
            // values cache on the parent to discover those inherited properties that
            // may need to be invalidated on the children nodes.
            if (!parent.IsSelfInheritanceParent)
            {
                DependencyObject inheritanceParent = parent.InheritanceParent;
                if (inheritanceParent != null)
                {
                    parentEffectiveValues      = inheritanceParent.EffectiveValues;
                    parentEffectiveValuesCount = inheritanceParent.EffectiveValuesCount;
                    inheritablePropertiesCount = inheritanceParent.InheritableEffectiveValuesCount;
                }
            }
            else
            {
                parentEffectiveValues      = parent.EffectiveValues;
                parentEffectiveValuesCount = parent.EffectiveValuesCount;
                inheritablePropertiesCount = parent.InheritableEffectiveValuesCount;
            }

            FrugalObjectList <DependencyProperty> inheritableProperties = new FrugalObjectList <DependencyProperty>((int)inheritablePropertiesCount);

            if (inheritablePropertiesCount == 0)
            {
                return(inheritableProperties);
            }

            _rootInheritableValues = new InheritablePropertyChangeInfo[(int)inheritablePropertiesCount];
            int inheritableIndex = 0;

            FrameworkObject foParent = new FrameworkObject(parent);

            for (uint i = 0; i < parentEffectiveValuesCount; i++)
            {
                // Add all the inheritable properties from the effectiveValues
                // cache to the TreeStateCache on the parent
                EffectiveValueEntry entry = parentEffectiveValues[i];
                DependencyProperty  dp    = DependencyProperty.RegisteredPropertyList.List[entry.PropertyIndex];

                // There are UncommonFields also stored in the EffectiveValues cache. We need to exclude those.
                if ((dp != null) && dp.IsPotentiallyInherited)
                {
                    PropertyMetadata metadata = dp.GetMetadata(parent.DependencyObjectType);
                    if (metadata != null && metadata.IsInherited)
                    {
                        Debug.Assert(!inheritableProperties.Contains(dp), "EffectiveValues cache must not contains duplicate entries for the same DP");

                        FrameworkPropertyMetadata fMetadata = (FrameworkPropertyMetadata)metadata;

                        // Children do not need to inherit properties across a tree boundary
                        // unless the property is set to override this behavior.

                        if (!TreeWalkHelper.SkipNow(foParent.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior)
                        {
                            inheritableProperties.Add(dp);

                            EffectiveValueEntry oldEntry;
                            EffectiveValueEntry newEntry;

                            oldEntry = d.GetValueEntry(
                                d.LookupEntry(dp.GlobalIndex),
                                dp,
                                dp.GetMetadata(treeObjDOT),
                                RequestFlags.DeferredReferences);

                            if (isAddOperation)
                            {
                                // set up the new value
                                newEntry = entry;

                                if ((newEntry.BaseValueSourceInternal != BaseValueSourceInternal.Default) || newEntry.HasModifiers)
                                {
                                    newEntry = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                                    newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
                                }
                            }
                            else
                            {
                                newEntry = new EffectiveValueEntry();
                            }


                            _rootInheritableValues[inheritableIndex++] =
                                new InheritablePropertyChangeInfo(d, dp, oldEntry, newEntry);

                            if (inheritablePropertiesCount == inheritableIndex)
                            {
                                // no more inheritable properties, bail early
                                break;
                            }
                        }
                    }
                }
            }

            return(inheritableProperties);
        }
Exemplo n.º 14
0
        // Invalidate all the properties that may have changed as a result of
        //  changing this element's parent in the logical (and sometimes visual tree.)
        internal FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            AncestorChangeInProgress = true;

            InVisibilityCollapsedTree = false;  // False == we don't know whether we're in a visibility collapsed tree.

            if (parentTreeState.TopmostCollapsedParentNode == null)
            {
                // There is no ancestor node with Visibility=Collapsed.
                //  See if "fe" is the root of a collapsed subtree.
                if (Visibility == Visibility.Collapsed)
                {
                    // This is indeed the root of a collapsed subtree.
                    //  remember this information as we proceed on the tree walk.
                    parentTreeState.TopmostCollapsedParentNode = this;

                    // Yes, this FE node is in a visibility collapsed subtree.
                    InVisibilityCollapsedTree = true;
                }
            }
            else
            {
                // There is an ancestor node somewhere above us with
                //  Visibility=Collapsed.  We're in a visibility collapsed subtree.
                InVisibilityCollapsedTree = true;
            }


            try
            {
                // Style property is a special case of a non-inherited property that needs
                // invalidation for parent changes. Invalidate StyleProperty if it hasn't been
                // locally set because local value takes precedence over implicit references
                if (IsInitialized && !HasLocalStyle && (this != parentTreeState.Root))
                {
                    UpdateStyleProperty();
                }

                Style            selfStyle       = null;
                Style            selfThemeStyle  = null;
                DependencyObject templatedParent = null;

                int         childIndex         = -1;
                ChildRecord childRecord        = new ChildRecord();
                bool        isChildRecordValid = false;

                selfStyle       = Style;
                selfThemeStyle  = ThemeStyle;
                templatedParent = TemplatedParent;
                childIndex      = TemplateChildIndex;

                // StyleProperty could have changed during invalidation of ResourceReferenceExpressions if it
                // were locally set or during the invalidation of unresolved implicitly referenced style
                bool hasStyleChanged = HasStyleChanged;

                // Fetch selfStyle, hasStyleChanged and childIndex for the current node
                FrameworkElement.GetTemplatedParentChildRecord(templatedParent, childIndex, out childRecord, out isChildRecordValid);

                FrameworkElement        parentFE;
                FrameworkContentElement parentFCE;
                bool hasParent = FrameworkElement.GetFrameworkParent(this, out parentFE, out parentFCE);

                DependencyObject    parent = null;
                InheritanceBehavior parentInheritanceBehavior = InheritanceBehavior.Default;
                if (hasParent)
                {
                    if (parentFE != null)
                    {
                        parent = parentFE;
                        parentInheritanceBehavior = parentFE.InheritanceBehavior;
                    }
                    else
                    {
                        parent = parentFCE;
                        parentInheritanceBehavior = parentFCE.InheritanceBehavior;
                    }
                }

                if (!TreeWalkHelper.SkipNext(InheritanceBehavior) && !TreeWalkHelper.SkipNow(parentInheritanceBehavior))
                {
                    // Synchronize InheritanceParent
                    this.SynchronizeInheritanceParent(parent);
                }
                else if (!IsSelfInheritanceParent)
                {
                    // Set IsSelfInheritanceParet on the root node at a tree boundary
                    // so that all inheritable properties are cached on it.
                    SetIsSelfInheritanceParent();
                }

                // Loop through all cached inheritable properties for the parent to see if they should be invalidated.
                return(TreeWalkHelper.InvalidateTreeDependentProperties(parentTreeState, /* fe = */ this, /* fce = */ null, selfStyle, selfThemeStyle,
                                                                        ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent));
            }
            finally
            {
                AncestorChangeInProgress  = false;
                InVisibilityCollapsedTree = false;  // 'false' just means 'we don't know' - see comment at definition of the flag.
            }
        }
Exemplo n.º 15
0
        /// <summary>
        ///     Invoked when logical parent is changed.  This just
        ///     sets the parent pointer.
        /// </summary>
        /// <remarks>
        ///     A parent change is considered catastrohpic and results in a large
        ///     amount of invalidations and tree traversals. <cref see="DependencyFastBuild"/>
        ///     is recommended to reduce the work necessary to build a tree
        /// </remarks>
        /// <param name="newParent">
        ///     New parent that was set
        /// </param>
        internal void ChangeLogicalParent(DependencyObject newParent)
        {
            ///////////////////
            // OnNewParent:
            ///////////////////

            //
            // -- Approved By The Core Team --
            //
            // Do not allow foreign threads to change the tree.
            // (This is a noop if this object is not assigned to a Dispatcher.)
            //
            // We also need to ensure that the tree is homogenous with respect
            // to the dispatchers that the elements belong to.
            //
            this.VerifyAccess();
            if (newParent != null)
            {
                newParent.VerifyAccess();
            }

            // Logical Parent must first be dropped before you are attached to a newParent
            // This mitigates illegal tree state caused by logical child stealing as illustrated in bug 970706
            if (_parent != null && newParent != null && _parent != newParent)
            {
                throw new System.InvalidOperationException(SR.Get(SRID.HasLogicalParent));
            }

            // Trivial check to avoid loops
            if (newParent == this)
            {
                throw new System.InvalidOperationException(SR.Get(SRID.CannotBeSelfParent));
            }

            // Logical Parent implies no InheritanceContext
            if (newParent != null)
            {
                ClearInheritanceContext();
            }

            IsParentAnFE = newParent is FrameworkElement;

            DependencyObject oldParent = _parent;

            OnNewParent(newParent);

            // Update Has[Loaded/Unloaded]Handler Flags
            BroadcastEventHelper.AddOrRemoveHasLoadedChangeHandlerFlag(this, oldParent, newParent);



            ///////////////////
            // OnParentChanged:
            ///////////////////

            // Invalidate relevant properties for this subtree
            DependencyObject parent = (newParent != null) ? newParent : oldParent;

            TreeWalkHelper.InvalidateOnTreeChange(/* fe = */ this, /* fce = */ null, parent, (newParent != null));

            // If no one has called BeginInit then mark the element initialized and fire Initialized event
            // (non-parser programmatic tree building scenario)
            TryFireInitialized();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Elements that arent connected to the tree do not receive theme change notifications.
 /// We leave it upto the app author to listen for such changes and invoke this method on
 /// elements that they know that arent connected to the tree. This method will update the
 /// DefaultStyle for the subtree starting at the current instance.
 /// </summary>
 public void UpdateDefaultStyle()
 {
     TreeWalkHelper.InvalidateOnResourcesChange(/* fe = */ this, /* fce = */ null, ResourcesChangeInfo.ThemeChangeInfo);
 }
Exemplo n.º 17
0
 // Token: 0x06000C68 RID: 3176 RVA: 0x0002E666 File Offset: 0x0002C866
 private static bool OnResourcesChangedCallback(DependencyObject d, ResourcesChangeInfo info, bool visitedViaVisualTree)
 {
     TreeWalkHelper.OnResourcesChanged(d, info, true);
     return(true);
 }
Exemplo n.º 18
0
        // Invalidate all the properties that may have changed as a result of
        //  changing this element's parent in the logical (and sometimes visual tree.)
        internal FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            AncestorChangeInProgress = true;


            try
            {
                // Style property is a special case of a non-inherited property that needs
                // invalidation for parent changes. Invalidate StyleProperty if it hasn't been
                // locally set because local value takes precedence over implicit references
                if (!HasLocalStyle && (this != parentTreeState.Root))
                {
                    UpdateStyleProperty();
                }

                Style            selfStyle       = null;
                Style            selfThemeStyle  = null;
                DependencyObject templatedParent = null;

                int         childIndex         = -1;
                ChildRecord childRecord        = new ChildRecord();
                bool        isChildRecordValid = false;

                selfStyle       = Style;
                selfThemeStyle  = ThemeStyle;
                templatedParent = TemplatedParent;
                childIndex      = TemplateChildIndex;

                // StyleProperty could have changed during invalidation of ResourceReferenceExpressions if it
                // were locally set or during the invalidation of unresolved implicitly referenced style
                bool hasStyleChanged = HasStyleChanged;

                // Fetch selfStyle, hasStyleChanged and childIndex for the current node
                FrameworkElement.GetTemplatedParentChildRecord(templatedParent, childIndex, out childRecord, out isChildRecordValid);

                FrameworkElement        parentFE;
                FrameworkContentElement parentFCE;
                bool hasParent = FrameworkElement.GetFrameworkParent(this, out parentFE, out parentFCE);

                DependencyObject    parent = null;
                InheritanceBehavior parentInheritanceBehavior = InheritanceBehavior.Default;
                if (hasParent)
                {
                    if (parentFE != null)
                    {
                        parent = parentFE;
                        parentInheritanceBehavior = parentFE.InheritanceBehavior;
                    }
                    else
                    {
                        parent = parentFCE;
                        parentInheritanceBehavior = parentFCE.InheritanceBehavior;
                    }
                }

                if (!TreeWalkHelper.SkipNext(InheritanceBehavior) && !TreeWalkHelper.SkipNow(parentInheritanceBehavior))
                {
                    // Synchronize InheritanceParent
                    this.SynchronizeInheritanceParent(parent);
                }
                else if (!IsSelfInheritanceParent)
                {
                    // Set IsSelfInheritanceParet on the root node at a tree boundary
                    // so that all inheritable properties are cached on it.
                    SetIsSelfInheritanceParent();
                }

                // Loop through all cached inheritable properties for the parent to see if they should be invalidated.
                return(TreeWalkHelper.InvalidateTreeDependentProperties(parentTreeState, /* fe = */ null, /* fce = */ this, selfStyle, selfThemeStyle,
                                                                        ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent));
            }
            finally
            {
                AncestorChangeInProgress = false;
            }
        }
Exemplo n.º 19
0
        // Token: 0x06000C69 RID: 3177 RVA: 0x0002E674 File Offset: 0x0002C874
        internal static void OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, bool raiseResourceChangedEvent)
        {
            bool            flag                      = info.Contains(d.DependencyObjectType.SystemType, true);
            bool            isThemeChange             = info.IsThemeChange;
            bool            isStyleResourcesChange    = info.IsStyleResourcesChange;
            bool            isTemplateResourcesChange = info.IsTemplateResourcesChange;
            bool            flag2                     = info.Container == d;
            FrameworkObject frameworkObject           = new FrameworkObject(d);

            if (info.IsResourceAddOperation || info.IsCatastrophicDictionaryChange)
            {
                frameworkObject.SetShouldLookupImplicitStyles();
            }
            if (frameworkObject.IsFE)
            {
                FrameworkElement fe = frameworkObject.FE;
                fe.HasStyleChanged     = false;
                fe.HasStyleInvalidated = false;
                fe.HasTemplateChanged  = false;
                if (info.IsImplicitDataTemplateChange)
                {
                    ContentPresenter contentPresenter = fe as ContentPresenter;
                    if (contentPresenter != null)
                    {
                        contentPresenter.ReevaluateTemplate();
                    }
                }
                if (fe.HasResourceReference)
                {
                    TreeWalkHelper.InvalidateResourceReferences(fe, info);
                    if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2)
                    {
                        TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag);
                    }
                }
                else if (flag && (fe.HasImplicitStyleFromResources || fe.Style == FrameworkElement.StyleProperty.GetMetadata(fe.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2))
                {
                    fe.UpdateStyleProperty();
                }
                if (isThemeChange)
                {
                    fe.UpdateThemeStyleProperty();
                }
                if (raiseResourceChangedEvent && fe.PotentiallyHasMentees)
                {
                    fe.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info));
                    return;
                }
            }
            else
            {
                FrameworkContentElement fce = frameworkObject.FCE;
                fce.HasStyleChanged     = false;
                fce.HasStyleInvalidated = false;
                if (fce.HasResourceReference)
                {
                    TreeWalkHelper.InvalidateResourceReferences(fce, info);
                    if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2)
                    {
                        TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag);
                    }
                }
                else if (flag && (fce.HasImplicitStyleFromResources || fce.Style == FrameworkContentElement.StyleProperty.GetMetadata(fce.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2))
                {
                    fce.UpdateStyleProperty();
                }
                if (isThemeChange)
                {
                    fce.UpdateThemeStyleProperty();
                }
                if (raiseResourceChangedEvent && fce.PotentiallyHasMentees)
                {
                    fce.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info));
                }
            }
        }
Exemplo n.º 20
0
        // Token: 0x06000C6D RID: 3181 RVA: 0x0002EB78 File Offset: 0x0002CD78
        private static bool OnInheritablePropertyChanged(DependencyObject d, InheritablePropertyChangeInfo info, bool visitedViaVisualTree)
        {
            DependencyProperty  property = info.Property;
            EffectiveValueEntry oldEntry = info.OldEntry;
            EffectiveValueEntry newEntry = info.NewEntry;
            InheritanceBehavior inheritanceBehavior;
            bool flag  = TreeWalkHelper.IsInheritanceNode(d, property, out inheritanceBehavior);
            bool flag2 = TreeWalkHelper.IsForceInheritedProperty(property);

            if (!flag || (TreeWalkHelper.SkipNext(inheritanceBehavior) && !flag2))
            {
                return(inheritanceBehavior == InheritanceBehavior.Default || flag2);
            }
            PropertyMetadata metadata   = property.GetMetadata(d);
            EntryIndex       entryIndex = d.LookupEntry(property.GlobalIndex);

            if (!d.IsSelfInheritanceParent)
            {
                DependencyObject    frameworkParent      = FrameworkElement.GetFrameworkParent(d);
                InheritanceBehavior inheritanceBehavior2 = InheritanceBehavior.Default;
                if (frameworkParent != null)
                {
                    FrameworkObject frameworkObject = new FrameworkObject(frameworkParent, true);
                    inheritanceBehavior2 = frameworkObject.InheritanceBehavior;
                }
                if (!TreeWalkHelper.SkipNext(inheritanceBehavior) && !TreeWalkHelper.SkipNow(inheritanceBehavior2))
                {
                    d.SynchronizeInheritanceParent(frameworkParent);
                }
                if (oldEntry.BaseValueSourceInternal == BaseValueSourceInternal.Unknown)
                {
                    oldEntry = EffectiveValueEntry.CreateDefaultValueEntry(property, metadata.GetDefaultValue(d, property));
                }
            }
            else
            {
                oldEntry = d.GetValueEntry(entryIndex, property, metadata, RequestFlags.RawEntry);
            }
            if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
            {
                if (visitedViaVisualTree && FrameworkElement.DType.IsInstanceOfType(d))
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(d);
                    if (parent != null)
                    {
                        DependencyObject parent2 = VisualTreeHelper.GetParent(d);
                        if (parent2 != null && parent2 != parent)
                        {
                            return(false);
                        }
                    }
                }
                return((d.UpdateEffectiveValue(entryIndex, property, metadata, oldEntry, ref newEntry, false, false, OperationType.Inherit) & (UpdateResult)5) == UpdateResult.ValueChanged);
            }
            if (flag2)
            {
                newEntry = new EffectiveValueEntry(property, FullValueSource.IsCoerced);
                return((d.UpdateEffectiveValue(d.LookupEntry(property.GlobalIndex), property, metadata, oldEntry, ref newEntry, false, false, OperationType.Inherit) & (UpdateResult)5) == UpdateResult.ValueChanged);
            }
            return(false);
        }
Exemplo n.º 21
0
        // Token: 0x06000C59 RID: 3161 RVA: 0x0002DFDC File Offset: 0x0002C1DC
        internal FrugalObjectList <DependencyProperty> CreateParentInheritableProperties(DependencyObject d, DependencyObject parent, bool isAddOperation)
        {
            if (parent == null)
            {
                return(new FrugalObjectList <DependencyProperty>(0));
            }
            DependencyObjectType dependencyObjectType = d.DependencyObjectType;

            EffectiveValueEntry[] array = null;
            uint num  = 0U;
            uint num2 = 0U;

            if (!parent.IsSelfInheritanceParent)
            {
                DependencyObject inheritanceParent = parent.InheritanceParent;
                if (inheritanceParent != null)
                {
                    array = inheritanceParent.EffectiveValues;
                    num   = inheritanceParent.EffectiveValuesCount;
                    num2  = inheritanceParent.InheritableEffectiveValuesCount;
                }
            }
            else
            {
                array = parent.EffectiveValues;
                num   = parent.EffectiveValuesCount;
                num2  = parent.InheritableEffectiveValuesCount;
            }
            FrugalObjectList <DependencyProperty> frugalObjectList = new FrugalObjectList <DependencyProperty>((int)num2);

            if (num2 == 0U)
            {
                return(frugalObjectList);
            }
            this._rootInheritableValues = new InheritablePropertyChangeInfo[num2];
            int             num3            = 0;
            FrameworkObject frameworkObject = new FrameworkObject(parent);

            for (uint num4 = 0U; num4 < num; num4 += 1U)
            {
                EffectiveValueEntry effectiveValueEntry = array[(int)num4];
                DependencyProperty  dependencyProperty  = DependencyProperty.RegisteredPropertyList.List[effectiveValueEntry.PropertyIndex];
                if (dependencyProperty != null && dependencyProperty.IsPotentiallyInherited)
                {
                    PropertyMetadata metadata = dependencyProperty.GetMetadata(parent.DependencyObjectType);
                    if (metadata != null && metadata.IsInherited)
                    {
                        FrameworkPropertyMetadata frameworkPropertyMetadata = (FrameworkPropertyMetadata)metadata;
                        if (!TreeWalkHelper.SkipNow(frameworkObject.InheritanceBehavior) || frameworkPropertyMetadata.OverridesInheritanceBehavior)
                        {
                            frugalObjectList.Add(dependencyProperty);
                            EffectiveValueEntry valueEntry = d.GetValueEntry(d.LookupEntry(dependencyProperty.GlobalIndex), dependencyProperty, dependencyProperty.GetMetadata(dependencyObjectType), RequestFlags.DeferredReferences);
                            EffectiveValueEntry newEntry;
                            if (isAddOperation)
                            {
                                newEntry = effectiveValueEntry;
                                if (newEntry.BaseValueSourceInternal != BaseValueSourceInternal.Default || newEntry.HasModifiers)
                                {
                                    newEntry = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
                                    newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
                                }
                            }
                            else
                            {
                                newEntry = default(EffectiveValueEntry);
                            }
                            this._rootInheritableValues[num3++] = new InheritablePropertyChangeInfo(d, dependencyProperty, valueEntry, newEntry);
                            if ((ulong)num2 == (ulong)((long)num3))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(frugalObjectList);
        }
Exemplo n.º 22
0
        // Token: 0x06000C61 RID: 3169 RVA: 0x0002E1F8 File Offset: 0x0002C3F8
        internal static void InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, bool isAddOperation)
        {
            FrameworkObject frameworkObject = new FrameworkObject(parent);

            if (!frameworkObject.IsValid)
            {
                parent = frameworkObject.FrameworkParent.DO;
            }
            FrameworkObject frameworkObject2 = new FrameworkObject(fe, fce);

            if (isAddOperation)
            {
                frameworkObject2.SetShouldLookupImplicitStyles();
            }
            frameworkObject2.Reset(frameworkObject2.TemplatedParent);
            frameworkObject2.HasTemplateChanged = false;
            DependencyObject dependencyObject = (fe != null) ? fe : fce;

            if (fe != null)
            {
                if (fe.IsInitialized && !fe.HasLocalStyle)
                {
                    fe.HasStyleChanged          = false;
                    fe.HasStyleInvalidated      = false;
                    fe.HasTemplateChanged       = false;
                    fe.AncestorChangeInProgress = true;
                    fe.UpdateStyleProperty();
                    fe.AncestorChangeInProgress = false;
                }
            }
            else if (!fce.HasLocalStyle)
            {
                fce.HasStyleChanged          = false;
                fce.HasStyleInvalidated      = false;
                fce.AncestorChangeInProgress = true;
                fce.UpdateStyleProperty();
                fce.AncestorChangeInProgress = false;
            }
            if (TreeWalkHelper.HasChildren(fe, fce))
            {
                FrameworkContextData frameworkContextData = FrameworkContextData.From(dependencyObject.Dispatcher);
                if (frameworkContextData.WasNodeVisited(dependencyObject, TreeWalkHelper.TreeChangeDelegate))
                {
                    return;
                }
                TreeChangeInfo data = new TreeChangeInfo(dependencyObject, parent, isAddOperation);
                PrePostDescendentsWalker <TreeChangeInfo> prePostDescendentsWalker = new PrePostDescendentsWalker <TreeChangeInfo>(TreeWalkPriority.LogicalTree, TreeWalkHelper.TreeChangeDelegate, TreeWalkHelper.TreeChangePostDelegate, data);
                frameworkContextData.AddWalker(TreeWalkHelper.TreeChangeDelegate, prePostDescendentsWalker);
                try
                {
                    prePostDescendentsWalker.StartWalk(dependencyObject);
                    return;
                }
                finally
                {
                    frameworkContextData.RemoveWalker(TreeWalkHelper.TreeChangeDelegate, prePostDescendentsWalker);
                }
            }
            TreeChangeInfo info = new TreeChangeInfo(dependencyObject, parent, isAddOperation);

            TreeWalkHelper.OnAncestorChanged(fe, fce, info);
            bool visitedViaVisualTree = false;

            TreeWalkHelper.OnPostAncestorChanged(dependencyObject, info, visitedViaVisualTree);
        }