コード例 #1
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);
        }
コード例 #2
0
        // Token: 0x06007608 RID: 30216 RVA: 0x0021A9AC File Offset: 0x00218BAC
        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);
            }
            FrameworkObject frameworkObject = new FrameworkObject(d);

            frameworkObject.Reset(frameworkObject.GetPreferVisualParent(true).DO);
            while (frameworkObject.DO != null)
            {
                if (isTracing)
                {
                    TraceData.Trace(TraceEventType.Warning, TraceData.AncestorLookup(new object[]
                    {
                        type.Name,
                        TraceData.Identify(frameworkObject.DO)
                    }));
                }
                if (type.IsInstanceOfType(frameworkObject.DO) && --level <= 0)
                {
                    break;
                }
                frameworkObject.Reset(frameworkObject.PreferVisualParent.DO);
            }
            return(frameworkObject.DO);
        }
コード例 #3
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);
        }
コード例 #4
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;
                        }
                    }

                    // if the logical parent is a ContentControl whose content
                    // points right back, move to the ContentControl.   This is the
                    // m---- equivalent of having the ContentControl as the TemplatedParent.
                    // (The InheritanceBehavior clause prevents this for cases where the
                    // parent ContentControl imposes a barrier, e.g. Frame)
                    if (dd == null && scopeOwner == null)
                    {
                        ContentControl cc = LogicalTreeHelper.GetParent(fo.DO) as ContentControl;
                        if (cc != null && cc.Content == fo.DO && cc.InheritanceBehavior == InheritanceBehavior.Default)
                        {
                            dd = cc;
                        }
                    }

                    // 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);
        }
コード例 #5
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);
        }
コード例 #6
0
        // Token: 0x060075FB RID: 30203 RVA: 0x0021A3F0 File Offset: 0x002185F0
        internal override object GetObject(DependencyObject d, ObjectRefArgs args)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            object obj = null;

            if (args.ResolveNamesInTemplate)
            {
                FrameworkElement frameworkElement = d as FrameworkElement;
                if (frameworkElement != null && frameworkElement.TemplateInternal != null)
                {
                    obj = Helper.FindNameInTemplate(this._name, d);
                    if (args.IsTracing)
                    {
                        TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQueryTemplate(new object[]
                        {
                            this._name,
                            TraceData.Identify(d)
                        }));
                    }
                }
                if (obj == null)
                {
                    args.NameResolvedInOuterScope = true;
                }
            }
            FrameworkObject frameworkObject = new FrameworkObject(d);

            while (obj == null && frameworkObject.DO != null)
            {
                DependencyObject dependencyObject;
                obj = frameworkObject.FindName(this._name, out dependencyObject);
                if (d == dependencyObject && d is IComponentConnector && d.ReadLocalValue(NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue)
                {
                    DependencyObject dependencyObject2 = LogicalTreeHelper.GetParent(d);
                    if (dependencyObject2 == null)
                    {
                        dependencyObject2 = Helper.FindMentor(d.InheritanceContext);
                    }
                    if (dependencyObject2 != null)
                    {
                        obj = null;
                        frameworkObject.Reset(dependencyObject2);
                        continue;
                    }
                }
                if (args.IsTracing)
                {
                    TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQuery(new object[]
                    {
                        this._name,
                        TraceData.Identify(frameworkObject.DO)
                    }));
                }
                if (obj == null)
                {
                    args.NameResolvedInOuterScope = true;
                    FrameworkObject  frameworkObject2  = new FrameworkObject(dependencyObject);
                    DependencyObject dependencyObject3 = frameworkObject2.TemplatedParent;
                    if (dependencyObject3 == null)
                    {
                        Panel panel = frameworkObject.FrameworkParent.DO as Panel;
                        if (panel != null && panel.IsItemsHost)
                        {
                            dependencyObject3 = panel;
                        }
                    }
                    if (dependencyObject3 == null && dependencyObject == null)
                    {
                        ContentControl contentControl = LogicalTreeHelper.GetParent(frameworkObject.DO) as ContentControl;
                        if (contentControl != null && contentControl.Content == frameworkObject.DO && contentControl.InheritanceBehavior == InheritanceBehavior.Default)
                        {
                            dependencyObject3 = contentControl;
                        }
                    }
                    if (dependencyObject3 == null && dependencyObject == null)
                    {
                        dependencyObject3 = frameworkObject.DO;
                        for (;;)
                        {
                            DependencyObject dependencyObject4 = LogicalTreeHelper.GetParent(dependencyObject3);
                            if (dependencyObject4 == null)
                            {
                                dependencyObject4 = Helper.FindMentor(dependencyObject3.InheritanceContext);
                            }
                            if (dependencyObject4 == null)
                            {
                                break;
                            }
                            dependencyObject3 = dependencyObject4;
                        }
                        ContentPresenter contentPresenter = VisualTreeHelper.IsVisualType(dependencyObject3) ? (VisualTreeHelper.GetParent(dependencyObject3) as ContentPresenter) : null;
                        dependencyObject3 = ((contentPresenter != null && contentPresenter.TemplateInternal.CanBuildVisualTree) ? contentPresenter : null);
                    }
                    frameworkObject.Reset(dependencyObject3);
                }
            }
            if (obj == null)
            {
                obj = DependencyProperty.UnsetValue;
                args.NameResolvedInOuterScope = false;
            }
            return(obj);
        }