Treeview如何判断用户何时通过拖动节点重新组织树视图 [英] Treeview how do I tell when the user reorganizes the treeview by dragging nodes
问题描述
我有一个用户可以编辑的TreeView。我需要知道它何时发生变化,以便我能坚持下去。我做了添加和删除,所以这没问题。但是用户也可以通过拖放节点来重构树。我无法确定在发生这种情况时应该聆听什么事件。
我尝试了什么:
我尝试过拖放事件,但是他们没有被发现。我想TreeView会自己吃掉它们。我已经考虑过继承TreeViewNode并覆盖可能在这种情况下使用的所有Children IList成员,但确定必须有更文明的方式。
I have a TreeView that the user can edit. I need to know whenever it changes so that I can persist it. I do the additions and deletions, so that is no problem. But the user can also restructure the tree by dragging and dropping the nodes. I haven't been able to determine what event(s) to listen for to tell when that is happening.
What I have tried:
I've tried the Drag and Drop events, but they were uncalled. I suppose the TreeView eats them itself. I've considered subclassing TreeViewNode and overriding all the Children IList members that could be used in that case, but was sure there must be a more civilised way.
推荐答案
TreeView本身不公开任何指示用户已更改树结构的事件,TreeView控件包装TreeViewList控件。该控件确实暴露了拖动事件,如DragItemStarting。因此解决方案是这样做:
While the TreeView itself does not expose any events that indicate that the user has changed the structure of the tree, the TreeView control wraps a TreeViewList control. That control does expose drag events, like DragItemStarting. So the solution is to do this:
<Style TargetType="TreeView">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<TreeViewList x:Name="ListControl"
DragItemsCompleted="DragItemsCompleted"
CanDragItems="True"
AllowDrop="True"
CanReorderItems="True">
感谢来自微软的Sunteen Wu的回答!
Thanks to Sunteen Wu from Microsoft for the answer!
也许是拖累和放大UWP TreeView不支持drop?
在uwp中的树视图之间拖放 - Stack Overflow [ ^ ]
Maybe drag & drop is not supported for a UWP TreeView?
Drag and drop between treeview in uwp - Stack Overflow[^]
这篇关于Treeview如何判断用户何时通过拖动节点重新组织树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!