• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 789
  • Last Modified:

Can Expression Bland behaviors be used to drag and drop nodes in a WPF TreeView control?

Is it possible to attach a behavior to a  WPF TreeView control to enable drag and drop on its nodes? And if there is ... how?
0
quentinA
Asked:
quentinA
  • 2
  • 2
1 Solution
 
saraganiCommented:
There is a behavior which let you do dragging (you see the  Visual of the item you drag).
I suppose that you can put this behavior on the DataTemplate of the treeviewitem, so each item will have it.

Now you only need to wait for the drop event on your drag scope.
0
 
saraganiCommented:
Hi, I've checked. It seems that MouseDragElementBehavior is not working as expected.
It doesn't work with buttons for example, and it also causing the TreeViewItem to be not selectable on mouse click.


<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfTree"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions" x:Class="WpfTree.MainWindow"
        Title="MainWindow" Height="350" Width="525" AllowDrop="True">
   
    <Window.Resources>
        <HierarchicalDataTemplate DataType="{x:Type local:TreeNode}" ItemsSource="{Binding Nodes}">
            <TextBlock Text="{Binding Text}" Margin="5,0">
                  <i:Interaction.Behaviors>
                          <il:MouseDragElementBehavior/>
                    </i:Interaction.Behaviors>        
                  </TextBlock>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <Grid>

        <TreeView ItemsSource="{Binding Nodes}">
        </TreeView>
    </Grid>
</Window>


I can suggest you to create your own code that does drag and drop. it is not hard.



Btw, Telerik has in their demos an example of dragging nodes in a tree.


0
 
quentinAAuthor Commented:
I found this example, and it seems to answer my question:
http://codeblitz.wordpress.com/2009/06/26/wpf-itemscontrol-drag-drop-behavior/
0
 
quentinAAuthor Commented:
shows details of how to use behaviors
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now