本文整理汇总了C#中System.Windows.Controls.ItemsControl.IsAncestorOf方法的典型用法代码示例。如果您正苦于以下问题:C# ItemsControl.IsAncestorOf方法的具体用法?C# ItemsControl.IsAncestorOf怎么用?C# ItemsControl.IsAncestorOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ItemsControl
的用法示例。
在下文中一共展示了ItemsControl.IsAncestorOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClosest
static UIElement GetClosest(
ItemsControl itemsControl,
List<DependencyObject> items,
Point position,
Orientation searchDirection)
{
UIElement closest = null;
var closestDistance = double.MaxValue;
foreach (var i in items)
{
var uiElement = i as UIElement;
if (uiElement != null)
{
if (!itemsControl.IsAncestorOf(uiElement))
continue;
var p = uiElement.TransformToAncestor(itemsControl).Transform(new Point(0, 0));
var distance = double.MaxValue;
if (itemsControl is TreeView)
{
var xDiff = position.X - p.X;
var yDiff = position.Y - p.Y;
var hyp = Math.Sqrt(Math.Pow(xDiff, 2d) + Math.Pow(yDiff, 2d));
distance = Math.Abs(hyp);
}
else
{
switch (searchDirection)
{
case Orientation.Horizontal:
distance = Math.Abs(position.X - p.X);
break;
case Orientation.Vertical:
distance = Math.Abs(position.Y - p.Y);
break;
}
}
if (distance < closestDistance)
{
closest = uiElement;
closestDistance = distance;
}
}
}
return closest;
}