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


C# FrameworkObject.GetPreferVisualParent方法代码示例

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


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

示例1: FindAncestorOfType

        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; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:40,代码来源:ObjectRef.cs

示例2: ContainerFromElement

        ///<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;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:34,代码来源:ItemsControl.cs


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