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


C# UIElement.GetVisualAncestor方法代码示例

本文整理汇总了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;
    }
开发者ID:Deadpikle,项目名称:gong-wpf-dragdrop,代码行数:13,代码来源:ItemsControlExtensions.cs

示例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;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:11,代码来源:ItemsControlExtensions.cs

示例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;
            }

//.........这里部分代码省略.........
开发者ID:jogibear9988,项目名称:gong-wpf-dragdrop,代码行数:101,代码来源:DropInfo.cs

示例4: GetItemContainer

 public static UIElement GetItemContainer(this ItemsControl itemsControl, UIElement child)
 {
   Type itemType = GetItemContainerType(itemsControl);
   return itemType == null ? null : (UIElement)child.GetVisualAncestor(itemType);
 }
开发者ID:modulexcite,项目名称:LoreSoft.Shared,代码行数:5,代码来源:ItemsControlExtensions.cs


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