跟踪在UWP TreeView中拖动的项目以及将其拖放到的项目非常重要。目前,我只能获得被拖动的项目。但是我无法检测到将其拖到哪个项目上或将其拖到哪个项目上。另外,最好预览一下放到哪个项目上,以便我可以做更多的动作(例如取消删除某些项目)。
这是我的扩展控件:
public class MyTreeView : TreeView
{
public MyTreeView()
{
this.DragItemsStarting += MyTreeView_DragItemsStarting; //execute ok
this.DragItemsCompleted += MyTreeView_DragItemsCompleted; //execute ok
this.DragEnter += MyTreeView_DragEnter; //does not execute?
this.Drop += MyTreeView_Drop; //does not execute?
this.DragOver += MyTreeView_DragOver; //does not execute?
}
//...
}
在xaml中:
<localdata:MyTreeView
x:Name="treeview" Grid.Row="2" ItemsSource="{Binding storageFolders,Mode=OneWay}"
Style="{StaticResource TreeViewStyle1}"
ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}"
SelectedItem="{Binding fileObject}"
SelectedIndex="{Binding IndexObj, Mode=TwoWay}"
>
</localdata:MyTreeView>
答案 0 :(得分:0)
这是设计使然,当其他DragOver
项悬停当前TreeView
时,将调用TreeView
。如果要实现cancel
功能,可以在TreeViewNode
事件处理程序中判断当前DragItems
对于DragItemsCompleted
是否正确,如下所示。
private void ListControl_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
{
foreach (var item in args.Items)
{
var node = TreeDataBound.NodeFromContainer(TreeDataBound.ContainerFromItem(item));
var parent = node.Parent;
//do some stuff judge the parent.
}
}