Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-04-19
4
Medium Priority
?
769 Views
Last Modified: 2013-11-12
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
Comment
Question by:quentinA
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:saragani
ID: 35427401
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
 
LVL 11

Expert Comment

by:saragani
ID: 35427945
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
 

Accepted Solution

by:
quentinA earned 0 total points
ID: 35500910
I found this example, and it seems to answer my question:
http://codeblitz.wordpress.com/2009/06/26/wpf-itemscontrol-drag-drop-behavior/
0
 

Author Closing Comment

by:quentinA
ID: 35704552
shows details of how to use behaviors
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question