Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 30-Jun-18 22:30pm
v2

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">


Thanks to Sunteen Wu from Microsoft for the answer!
 
Share this answer
 
Maybe drag & drop is not supported for a UWP TreeView?

Drag and drop between treeview in uwp - Stack Overflow[^]
 
Share this answer
 
Comments
Member 13022351 27-Jun-18 3:38am    
The UWP TreeView allows the user to move TreeViewNodes around the tree structure via drag and drop. It reorganizes the tree structure accordingly. For example, the user can drag a TreeViewNode from one parent to another parent thus altering the tree structure. My question is: how can I tell when this has happened? I haven't been able to find any events on TreeView that fire when this takes place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900