// Token: 0x0600648E RID: 25742 RVA: 0x001C36C8 File Offset: 0x001C18C8
        internal static FrameworkObject GetContainingFrameworkElement(DependencyObject current)
        {
            FrameworkObject result = new FrameworkObject(current);

            while (!result.IsValid && result.DO != null)
            {
                Visual         reference;
                ContentElement reference2;
                Visual3D       reference3;
                if ((reference = (result.DO as Visual)) != null)
                {
                    result.Reset(VisualTreeHelper.GetParent(reference));
                }
                else if ((reference2 = (result.DO as ContentElement)) != null)
                {
                    result.Reset(ContentOperations.GetParent(reference2));
                }
                else if ((reference3 = (result.DO as Visual3D)) != null)
                {
                    result.Reset(VisualTreeHelper.GetParent(reference3));
                }
                else
                {
                    result.Reset(null);
                }
            }
            return(result);
        }
Example #2
0
        internal static FrameworkObject GetContainingFrameworkElement(DependencyObject current)
        {
            FrameworkObject fo = new FrameworkObject(current);

            while (!fo.IsValid && fo.DO != null)
            {
                // The current object is neither a FrameworkElement nor a
                // FrameworkContentElement.  We will now walk the "core"
                // tree looking for one.
                Visual         visual;
                Visual3D       visual3D;
                ContentElement ce;

                if ((visual = fo.DO as Visual) != null)
                {
                    fo.Reset(VisualTreeHelper.GetParent(visual));
                }
                else if ((ce = fo.DO as ContentElement) != null)
                {
                    fo.Reset(ContentOperations.GetParent(ce));
                }
                else if ((visual3D = fo.DO as Visual3D) != null)
                {
                    fo.Reset(VisualTreeHelper.GetParent(visual3D));
                }
                else
                {
                    // The parent could be an application.
                    fo.Reset(null);
                }
            }

            return(fo);
        }
Example #3
0
        // returns the parent in the "prefer-visual" sense.
        // That is, this method
        //  1. prefers visual to logical parent (with InheritanceContext last)
        //  2. does not see parents whose InheritanceBehavior forbids it
        // Call with force=true to get the parent even if the current object doesn't
        // allow it via rule 2.
        internal FrameworkObject GetPreferVisualParent(bool force)
        {
            // If we're not allowed to move up from here, return null
            InheritanceBehavior inheritanceBehavior = force ? InheritanceBehavior.Default : this.InheritanceBehavior;

            if (inheritanceBehavior != InheritanceBehavior.Default)
            {
                return(new FrameworkObject(null));
            }

            FrameworkObject parent = GetRawPreferVisualParent();

            // make sure the parent allows itself to be found
            switch (parent.InheritanceBehavior)
            {
            case InheritanceBehavior.SkipToAppNow:
            case InheritanceBehavior.SkipToThemeNow:
            case InheritanceBehavior.SkipAllNow:
                parent.Reset(null);
                break;

            default:
                break;
            }

            return(parent);
        }
Example #4
0
        internal static bool IsEffectiveAncestor(DependencyObject d1, DependencyObject d2
#if TRACE_INHERITANCE_CONTEXT
                                                 , DependencyProperty dp
#endif
                                                 )
        {
#if TRACE_INHERITANCE_CONTEXT
            int depth = 0;
#endif
            for (FrameworkObject fo = new FrameworkObject(d2);
                 fo.DO != null;
                 fo.Reset(fo.EffectiveParent))
            {
                if (fo.DO == d1)
                {
#if TRACE_INHERITANCE_CONTEXT
                    Log("{0} creates cycle at depth {1}", LogIC(d2, dp, d1), depth);
#endif
                    return(true);
                }
#if TRACE_INHERITANCE_CONTEXT
                ++depth;
#endif
            }

            return(false);
        }
        // Token: 0x060064A1 RID: 25761 RVA: 0x001C3AA4 File Offset: 0x001C1CA4
        internal static bool IsEffectiveAncestor(DependencyObject d1, DependencyObject d2)
        {
            FrameworkObject frameworkObject = new FrameworkObject(d2);

            while (frameworkObject.DO != null)
            {
                if (frameworkObject.DO == d1)
                {
                    return(true);
                }
                frameworkObject.Reset(frameworkObject.EffectiveParent);
            }
            return(false);
        }
        // Token: 0x060064A6 RID: 25766 RVA: 0x001C3B9C File Offset: 0x001C1D9C
        internal FrameworkObject GetPreferVisualParent(bool force)
        {
            InheritanceBehavior inheritanceBehavior = force ? InheritanceBehavior.Default : this.InheritanceBehavior;

            if (inheritanceBehavior != InheritanceBehavior.Default)
            {
                return(new FrameworkObject(null));
            }
            FrameworkObject rawPreferVisualParent = this.GetRawPreferVisualParent();

            switch (rawPreferVisualParent.InheritanceBehavior)
            {
            case InheritanceBehavior.SkipToAppNow:
            case InheritanceBehavior.SkipToThemeNow:
            case InheritanceBehavior.SkipAllNow:
                rawPreferVisualParent.Reset(null);
                break;
            }
            return(rawPreferVisualParent);
        }
Example #7
0
        /// <summary> 
        ///     Invalidates all the properties on the nodes in the given sub-tree
        ///     that are referring to the resource[s] that are changing.
        /// </summary>
        internal static void InvalidateOnResourcesChange( 
            FrameworkElement        fe,
            FrameworkContentElement fce, 
            ResourcesChangeInfo     info) 
        {
            Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE."); 

            // We're interested in changes to the Template property that occur during
            // the walk - if the template has changed we don't need to invalidate
            // template-driven properties a second time.  The HasTemplateChanged property 
            // is cleared on the first visit to each node, so that it means "template
            // changed during the walk".  But one relevant node isn't visited during 
            // the walk - the templated parent of the initial node.  So we handle that now. 
            FrameworkObject fo = new FrameworkObject(fe, fce);
 
            fo.Reset(fo.TemplatedParent);
            fo.HasTemplateChanged = false;

            DependencyObject d = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce; 

            if (HasChildren(fe, fce)) 
            { 
                // Spin up a DescendentsWalker only when
                // the current node has children to walk 

                DescendentsWalker<ResourcesChangeInfo> walker = new DescendentsWalker<ResourcesChangeInfo>(
                    TreeWalkPriority.LogicalTree, ResourcesChangeDelegate, info);
 
                walker.StartWalk(d);
            } 
            else 
            {
                // Degenerate case when the current node is a leaf node and has no children. 

                OnResourcesChanged(d, info, true);
            }
        } 
Example #8
0
        /// <summary>
        ///     Invalidate inheritable properties and resource 
        ///     references during a tree change operation. 
        /// </summary>
        internal static void InvalidateOnTreeChange( 
            FrameworkElement        fe,
            FrameworkContentElement fce,
            DependencyObject        parent,
            bool                    isAddOperation) 
        {
            Debug.Assert(fe != null || fce != null, "Node with the tree change notification must be an FE or an FCE."); 
            Debug.Assert(parent != null, "Must have a parent that the current node is connected to or disconnected from."); 

            // If the tree change is for a non-FE/FCE parent then we need to find 
            // the nearest FE/FCE parent inorder to propagate inheritance correctly.
            FrameworkObject parentFO = new FrameworkObject(parent);
            if (!parentFO.IsValid)
            { 
                parent = parentFO.FrameworkParent.DO;
            } 
 
            // We're interested in changes to the Template property that occur during
            // the walk - if the template has changed we don't need to invalidate 
            // template-driven properties a second time.  The HasTemplateChanged property
            // is cleared on the first visit to each node, so that it means "template
            // changed during the walk".  But one relevant node isn't visited during
            // the walk - the templated parent of the initial node.  So we handle that now. 
            FrameworkObject fo = new FrameworkObject(fe, fce);
 
            // Synchronize the ShouldLookupImplicitStyles flag with respect to the parent here 
            // because for the root node of a tree change UpdateStyleProperty happens right here
            // in this method. And we need to have synchrnozed the ShouldLookupImplicitStyles 
            // before we re-query the Style property.

            if (isAddOperation)
            { 
                fo.SetShouldLookupImplicitStyles();
            } 
 
            fo.Reset(fo.TemplatedParent);
            fo.HasTemplateChanged = false; 

            DependencyObject d = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce;

            // during a tree walk to invalidate inherited properties, we typically 
            // call UpdateStyle from FE/FCE.InvalidateTreeDependentProperties.  But
            // for the root element of the tree change, we need to record old values 
            // for inherited properties before we've updated the inheritance parent; 
            // so do the updatestyle here before we record old values so that we
            // capture any updates provided by styles. 
            if (fe != null)
            {
                if (fe.IsInitialized && !fe.HasLocalStyle)
                { 
                    // Clear the HasStyleChanged flag
                    fe.HasStyleChanged = false; 
                    fe.HasStyleInvalidated = false; 
                    fe.HasTemplateChanged = false;
 
                    fe.AncestorChangeInProgress = true;
                    fe.UpdateStyleProperty();
                    fe.AncestorChangeInProgress = false;
                } 
            }
            else 
            { 
                if (!fce.HasLocalStyle)
                { 
                    // Clear the HasStyleChanged flag
                    fce.HasStyleChanged = false;
                    fce.HasStyleInvalidated = false;
 
                    fce.AncestorChangeInProgress = true;
                    fce.UpdateStyleProperty(); 
                    fce.AncestorChangeInProgress = false; 
                }
            } 

            if (HasChildren(fe, fce))
            {
                // Spin up a DescendentsWalker only when 
                // the current node has children to walk
 
                // If there is another tree walk that has already visited the 
                // current node then we do not need to re-walk its sub-tree.
                FrameworkContextData fcdata = FrameworkContextData.From(d.Dispatcher); 
                if (!fcdata.WasNodeVisited(d, TreeChangeDelegate))
                {
                    // The TreeChangeInfo object is used here to track
                    // information that we have because we're doing a tree walk. 
                    TreeChangeInfo parentInfo = new TreeChangeInfo(d, parent, isAddOperation);
 
                    // PrePostDescendentsWalker is used instead of the standard 
                    // DescendentsWalker because we need a "post" callback to know when
                    // to pop the parent's InheritableProperties cache from the stack. 
                    PrePostDescendentsWalker<TreeChangeInfo> walker = new PrePostDescendentsWalker<TreeChangeInfo>(
                        TreeWalkPriority.LogicalTree, TreeChangeDelegate, TreeChangePostDelegate, parentInfo);

                    fcdata.AddWalker(TreeChangeDelegate, walker); 

                    try 
                    { 
                        walker.StartWalk(d);
                    } 
                    finally
                    {
                        fcdata.RemoveWalker(TreeChangeDelegate, walker);
                    } 
                }
            } 
            else 
            {
                // Degenerate case when the current node is a leaf node and has no children. 

                TreeChangeInfo parentInfo = new TreeChangeInfo(d, parent, isAddOperation);

                // Degenerate case of OnAncestorChanged for a single node 
                OnAncestorChanged(fe, fce, parentInfo);
 
                // Degenerate case of OnPostAncestorChanged for a single node 
                OnPostAncestorChanged(d, parentInfo);
            } 
        }
        internal static bool IsEffectiveAncestor(DependencyObject d1, DependencyObject d2
#if TRACE_INHERITANCE_CONTEXT
                                , DependencyProperty dp
#endif
                                )
        {
#if TRACE_INHERITANCE_CONTEXT
            int depth = 0;
#endif
            for (   FrameworkObject fo = new FrameworkObject(d2);
                    fo.DO != null;
                    fo.Reset(fo.EffectiveParent))
            {
                if (fo.DO == d1)
                {
#if TRACE_INHERITANCE_CONTEXT
                    Log("{0} creates cycle at depth {1}", LogIC(d2, dp, d1), depth);
#endif
                    return true;
                }
#if TRACE_INHERITANCE_CONTEXT
                ++depth;
#endif
            }

            return false;
        }
        internal static FrameworkObject GetContainingFrameworkElement(DependencyObject current)
        {
            FrameworkObject fo = new FrameworkObject(current);

            while (!fo.IsValid && fo.DO != null)
            {
                // The current object is neither a FrameworkElement nor a
                // FrameworkContentElement.  We will now walk the "core"
                // tree looking for one.
                Visual visual;
                Visual3D visual3D;
                ContentElement ce;

                if ((visual = fo.DO as Visual) != null)
                {
                    fo.Reset(VisualTreeHelper.GetParent(visual));
                }
                else if ((ce = fo.DO as ContentElement) != null)
                {
                    fo.Reset(ContentOperations.GetParent(ce));
                }
                else if ((visual3D = fo.DO as Visual3D) != null)
                {
                    fo.Reset(VisualTreeHelper.GetParent(visual3D));
                }
                else
                {
                    // The parent could be an application.
                    fo.Reset(null);
                }
            }

            return fo;
        }
        // raise the SourceUpdatedEvent event (explicit polymorphism)
        internal static void OnSourceUpdated(DependencyObject d, DependencyProperty dp)
        {
            DataTransferEventArgs args = new DataTransferEventArgs(d, dp);
            args.RoutedEvent = Binding.SourceUpdatedEvent;
            FrameworkObject fo = new FrameworkObject(d);

            if (!fo.IsValid && d != null)
            {
                fo.Reset(Helper.FindMentor(d));
            }

            fo.RaiseEvent(args);
        }
Example #12
0
        private DependencyObject FindAncestorOfType(Type type, int level, DependencyObject d, bool isTracing)
        { 
            if (type == null) 
            {
                if (TraceData.IsEnabled) 
                    TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorTypeNotSpecified);
                return null;
            }
            if (level < 1) 
            {
                if (TraceData.IsEnabled) 
                    TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorLevelInvalid); 
                return null;
            } 

            // initialize search to start at the parent of the given DO
            FrameworkObject fo = new FrameworkObject(d);
            fo.Reset(fo.GetPreferVisualParent(true).DO); 

            while (fo.DO != null) 
            { 
                if (isTracing)
                { 
                    TraceData.Trace(TraceEventType.Warning,
                                        TraceData.AncestorLookup(
                                            type.Name,
                                            TraceData.Identify(fo.DO))); 
                }
 
                if (type.IsInstanceOfType(fo.DO))   // found it! 
                {
                    if (--level <= 0) 
                        break;
                }

                fo.Reset(fo.PreferVisualParent.DO); 
            }
 
            return fo.DO; 
        }
Example #13
0
        //-----------------------------------------------------
        //
        //  Public Methods
        // 
        //------------------------------------------------------
 
        /// <summary> Returns the referenced object. </summary> 
        /// <param name="d">Element defining context for the reference. </param>
        /// <param name="args">See ObjectRefArgs </param> 
        internal override object GetObject(DependencyObject d, ObjectRefArgs args)
        {
            if (d == null)
                throw new ArgumentNullException("d"); 

            object o = null; 
            if (args.ResolveNamesInTemplate) 
            {
                // look in container's template (if any) first 
                FrameworkElement fe = d as FrameworkElement;
                if (fe != null && fe.TemplateInternal != null)
                {
                    o = Helper.FindNameInTemplate(_name, d); 

                    if (args.IsTracing) 
                    { 
                        TraceData.Trace(TraceEventType.Warning,
                                            TraceData.ElementNameQueryTemplate( 
                                                _name,
                                                TraceData.Identify(d)));
                    }
                } 

                if (o == null) 
                { 
                    args.NameResolvedInOuterScope = true;
                } 
            }

            FrameworkObject fo = new FrameworkObject(d);
            while (o == null && fo.DO != null) 
            {
                DependencyObject scopeOwner; 
                o = fo.FindName(_name, out scopeOwner); 

                // if the original element is a scope owner, supports IComponentConnector, 
                // and has a parent, don't use the result of FindName.  The
                // element is probably an instance of a Xaml-subclassed control;
                // we want to resolve the name starting in the next outer scope.
                // (bug 1669408) 
                // Also, if the element's NavigationService property is locally
                // set, the element is the root of a navigation and should use the 
                // inner scope (bug 1765041) 
                if (d == scopeOwner && d is IComponentConnector &&
                    d.ReadLocalValue(System.Windows.Navigation.NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue) 
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(d);
                    if (parent == null)
                    { 
                        parent = Helper.FindMentor(d.InheritanceContext);
                    } 
 
                    if (parent != null)
                    { 
                        o = null;
                        fo.Reset(parent);
                        continue;
                    } 
                }
 
                if (args.IsTracing) 
                {
                    TraceData.Trace(TraceEventType.Warning, 
                                        TraceData.ElementNameQuery(
                                            _name,
                                            TraceData.Identify(fo.DO)));
                } 

                if (o == null) 
                { 
                    args.NameResolvedInOuterScope = true;
 
                    // move to the next outer namescope.
                    // First try TemplatedParent of the scope owner.
                    FrameworkObject foScopeOwner = new FrameworkObject(scopeOwner);
                    DependencyObject dd = foScopeOwner.TemplatedParent; 

                    // if that doesn't work, we could be at the top of 
                    // generated content for an ItemsControl.  If so, use 
                    // the (visual) parent - a panel.
                    if (dd == null) 
                    {
                        Panel panel = fo.FrameworkParent.DO as Panel;
                        if (panel != null && panel.IsItemsHost)
                        { 
                            dd = panel;
                        } 
                    } 

                    // next, see if we're in a logical tree attached directly 
                    // to a ContentPresenter.  This is the m---- equivalent of
                    // having the ContentPresenter as the TemplatedParent.
                    if (dd == null && scopeOwner == null)
                    { 
                        // go to the top of the logical subtree
                        DependencyObject parent; 
                        for (dd = fo.DO;;) 
                        {
                            parent = LogicalTreeHelper.GetParent(dd); 
                            if (parent == null)
                            {
                                parent = Helper.FindMentor(dd.InheritanceContext);
                            } 

                            if (parent == null) 
                                break; 

                            dd = parent; 
                        }

                        // if it's attached to a ContentPresenter, move to the CP
                        ContentPresenter cp = VisualTreeHelper.IsVisualType(dd) ? VisualTreeHelper.GetParent(dd) as ContentPresenter : null; 
                        dd = (cp != null && cp.TemplateInternal.CanBuildVisualTree) ? cp : null;
                    } 
 
                    fo.Reset(dd);
                } 
            }

            if (o == null)
            { 
                o = DependencyProperty.UnsetValue;
                args.NameResolvedInOuterScope = false; 
            } 

            return o; 
        }
Example #14
0
        ///<summary>
        /// Return the container that owns the given element.  If itemsControl
        /// is not null, return a container that belongs to the given ItemsControl.
        /// If itemsControl is null, return the closest container belonging to
        /// any ItemsControl.  Return null if no such container exists.
        ///</summary>
        public static DependencyObject ContainerFromElement(ItemsControl itemsControl, DependencyObject element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            // if the element is itself the desired container, return it
            if (IsContainerForItemsControl(element, itemsControl))
            {
                return element;
            }

            // start the tree walk at the element's parent
            FrameworkObject fo = new FrameworkObject(element);
            fo.Reset(fo.GetPreferVisualParent(true).DO);

            // walk up, stopping when we reach the desired container
            while (fo.DO != null)
            {
                if (IsContainerForItemsControl(fo.DO, itemsControl))
                {
                    break;
                }

                fo.Reset(fo.PreferVisualParent.DO);
            }

            return fo.DO;
        }