本文整理汇总了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;
}
示例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;
}