UWP TreeView DragEnter和DragOver事件不执行 [英] UWP TreeView DragEnter and DragOver events do not execute

查看:226
本文介绍了UWP TreeView DragEnter和DragOver事件不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟踪在UWP TreeView中拖动的项目以及将其拖放到的项目非常重要。目前,我只能获得被拖动的项目。但是我无法检测到将其拖动到哪个项目上或将其拖放到哪个项目上。另外,最好先预览一下放到哪个项目上,以便我可以执行更多操作(例如取消删除某些项目)。

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).

这是我的扩展控件:

    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>


推荐答案

这是设计使然, TreeView 项悬停在当前的 TreeView 上时,> DragOver 将被调用。如果要实现取消功能,则可以判断当前 TreeViewNode 对于 DragItems是否正确 DragItemsCompleted 事件处理程序中,如下所示。

It is by design , the DragOver will be invoked when other TreeView item hover current TreeView. If you want to realize cancel feature, you could judge if current TreeViewNode is correct for DragItems in the DragItemsCompleted event handler like the following .

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

这篇关于UWP TreeView DragEnter和DragOver事件不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆