本文整理汇总了C#中UIElement.GetVisualAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.GetVisualAncestor方法的具体用法?C# UIElement.GetVisualAncestor怎么用?C# UIElement.GetVisualAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIElement
的用法示例。
在下文中一共展示了UIElement.GetVisualAncestor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItemContainer
public static UIElement GetItemContainer(this ItemsControl itemsControl, UIElement child)
{
bool isItemContainer;
var itemType = GetItemContainerType(itemsControl, out isItemContainer);
if (itemType != null) {
return isItemContainer
? (UIElement)child.GetVisualAncestor(itemType, itemsControl)
: (UIElement)child.GetVisualAncestor(itemType, itemsControl.GetType());
}
return null;
}
示例2: GetItemContainer
public static UIElement GetItemContainer(this ItemsControl itemsControl, UIElement child)
{
Type itemType = GetItemContainerType(itemsControl);
if (itemType != null)
{
return (UIElement)child.GetVisualAncestor(itemType);
}
return null;
}
示例3: DropInfo
/// <summary>
/// Initializes a new instance of the DropInfo class.
/// </summary>
///
/// <param name="sender">
/// The sender of the drag event.
/// </param>
///
/// <param name="e">
/// The drag event.
/// </param>
///
/// <param name="dragInfo">
/// Information about the source of the drag, if the drag came from within the framework.
/// </param>
public DropInfo(object sender, DragEventArgs e, DragInfo dragInfo)
{
var dataFormat = DragDrop.DataFormat.Name;
this.Data = (e.Data.GetDataPresent(dataFormat)) ? e.Data.GetData(dataFormat) : e.Data;
this.DragInfo = dragInfo;
this.KeyStates = e.KeyStates;
this.VisualTarget = sender as UIElement;
// if there is no drop target, find another
if (!this.VisualTarget.IsDropTarget())
{
// try to find next element
var element = this.VisualTarget.TryGetNextAncestorDropTargetElement();
if (element != null)
{
this.VisualTarget = element;
}
}
// visual target can be null, so give us a point...
this.DropPosition = this.VisualTarget != null ? e.GetPosition(this.VisualTarget) : new Point();
if (this.VisualTarget is TabControl) {
if (!HitTestUtilities.HitTest4Type<TabPanel>(this.VisualTarget, this.DropPosition)) {
return;
}
}
if (this.VisualTarget is ItemsControl) {
var itemsControl = (ItemsControl)this.VisualTarget;
item = itemsControl.GetItemContainerAt(this.DropPosition);
if (item != null && item.GetVisualAncestor<ItemsControl>() != itemsControl)
item = null;
var directlyOverItem = item != null;
this.TargetGroup = itemsControl.FindGroup(this.DropPosition);
this.VisualTargetOrientation = itemsControl.GetItemsPanelOrientation();
this.VisualTargetFlowDirection = itemsControl.GetItemsPanelFlowDirection();
if (item == null) {
try
{
item = itemsControl.GetItemContainerAt(this.DropPosition, this.VisualTargetOrientation);
directlyOverItem = false;
}
catch(Exception)
{ }
}
if (item == null && this.TargetGroup != null && this.TargetGroup.IsBottomLevel)
{
var itemData = this.TargetGroup.Items.FirstOrDefault();
if (itemData != null)
{
item = itemsControl.ItemContainerGenerator.ContainerFromItem(itemData) as UIElement;
directlyOverItem = false;
}
}
if (item != null) {
itemParent = ItemsControl.ItemsControlFromItemContainer(item);
this.InsertIndex = itemParent.ItemContainerGenerator.IndexFromContainer(item);
this.TargetCollection = itemParent.ItemsSource ?? itemParent.Items;
var tvItem = item as TreeViewItem;
if (directlyOverItem || tvItem != null)
{
this.TargetItem = itemParent.ItemContainerGenerator.ItemFromContainer(item);
this.VisualTargetItem = item;
}
var itemRenderSize = item.RenderSize;
if (this.VisualTargetOrientation == Orientation.Vertical) {
var currentYPos = e.GetPosition(item).Y;
var targetHeight = itemRenderSize.Height;
if (currentYPos > targetHeight / 2) {
this.InsertIndex++;
this.InsertPosition = RelativeInsertPosition.AfterTargetItem;
} else {
this.InsertPosition = RelativeInsertPosition.BeforeTargetItem;
}
//.........这里部分代码省略.........
示例4: GetItemContainer
public static UIElement GetItemContainer(this ItemsControl itemsControl, UIElement child)
{
Type itemType = GetItemContainerType(itemsControl);
return itemType == null ? null : (UIElement)child.GetVisualAncestor(itemType);
}