It is very important that I can track which item is dragged in UWP TreeView and onto which item it is dropped. For now, I can get only item that is dragged. But I can not detect over which item it is dragged over or over which item it is dropped. Also it would be also good to know as preview which item is dropped onto so I can do more actions (for example cancel dropping on certain items).
Here is my extended control:
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?
}
//...
}
In the 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>
It is by design , the
DragOver
will be invoked when otherTreeView
item hover currentTreeView
. If you want to realizecancel
feature, you could judge if currentTreeViewNode
is correct forDragItems
in theDragItemsCompleted
event handler like the following .