我的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?
}
}
答案 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>