当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkObject.FindName方法代码示例

本文整理汇总了C#中MS.Internal.FrameworkObject.FindName方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkObject.FindName方法的具体用法?C# FrameworkObject.FindName怎么用?C# FrameworkObject.FindName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MS.Internal.FrameworkObject的用法示例。


在下文中一共展示了FrameworkObject.FindName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetObject

        //-----------------------------------------------------
        //
        //  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
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:ObjectRef.cs


注:本文中的MS.Internal.FrameworkObject.FindName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。