如何获取uwp树视图的节点上的节点?

时间:2018-10-20 15:18:22

标签: uwp uwp-xaml

我的TreeViewList控件针对_OnDragItemsCompleted具有以下事件

我想知道如何获得挂接的节点。 还是我使用了错误的事件?

  private void ListControl_OnDragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
  {

      var obj = args.Items.FirstOrDefault();  // just get the first for now
      var tvn = obj as TreeViewNode;
      var item = tvn.Content as StackPanel;
      var dep = item.DataContext as Department;

      if (args.DropResult == DataPackageOperation.Move)
      {
          // how do I get the dropped on?
      }

  }

1 个答案:

答案 0 :(得分:1)

当前,树状视图之间的拖放是预览。如果要获取DragItems,可以在DragItemsCompleted的{​​{1}}中为TreeViewList添加ControlTemplate事件处理程序。

TreeView

背后的代码

<Page.Resources>
    <Style TargetType="TreeView">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TreeView">
                    <TreeViewList x:Name="ListControl"
                                  ItemTemplate="{StaticResource TreeViewItemDataTemplate}"
                                  ItemContainerStyle="{StaticResource TreeViewItemStyle}"
                                  CanDragItems="True"
                                  AllowDrop="True"
                                  DragItemsCompleted="ListControl_DragItemsCompleted"
                                  CanReorderItems="True">
                        <TreeViewList.ItemContainerTransitions>
                            <TransitionCollection>
                                <ContentThemeTransition />
                                <ReorderThemeTransition />
                                <EntranceThemeTransition IsStaggeringEnabled="False" />
                            </TransitionCollection>
                        </TreeViewList.ItemContainerTransitions>
                    </TreeViewList>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Page.Resources>