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


C# ItemsControl.GetItemsPanelOrientation方法代码示例

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


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

示例1: 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;
        //System.Diagnostics.Debug.WriteLine(">>> Name = {0}", itemsControl.Name);
        // get item under the mouse
        item = itemsControl.GetItemContainerAt(this.DropPosition);
        var directlyOverItem = item != null;

        this.TargetGroup = itemsControl.FindGroup(this.DropPosition);
        this.VisualTargetOrientation = itemsControl.GetItemsPanelOrientation();
        this.VisualTargetFlowDirection = itemsControl.GetItemsPanelFlowDirection();

        if (item == null) {
          // ok, no item found, so maybe we can found an item at top, left, right or bottom
          item = itemsControl.GetItemContainerAt(this.DropPosition, this.VisualTargetOrientation);
          directlyOverItem = false;
        }

        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.VisualTargetOrientation = itemParent.GetItemsPanelOrientation();
          this.VisualTargetFlowDirection = itemParent.GetItemsPanelFlowDirection();

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

            if (currentYPos > targetHeight * 0.25 && currentYPos < targetHeight * 0.75) {
//.........这里部分代码省略.........
开发者ID:Livit,项目名称:Mailbird.Gong.WPF.DragDrop,代码行数:101,代码来源:DropInfo.cs


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