Enabling Drag and Drop

Here we have a simple tutorial to demonstrate the drag and drop functionality of the TreeView control.  In this example we have 2 folders containing 5 files.  When using the Liquid TreeView if you wish to use the drag and drop feature you must be using icons for your nodes you wish to drag.  This is essential as to drag a node you do so by clicking the node icon and drag the node to it's destination.


Implementing Drag and Drop

Here is the XAML for this demonstration:

<UserControl x:Class="TreeViewDragAndDrop.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:liquid="clr-namespace:Liquid;assembly=Liquid"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White" VerticalAlignment="Top" HorizontalAlignment="Left">
        <liquid:Tree x:Name="tree" EnableDragAndDrop="true" Drop="Tree_Drop" Width="300" Height="151" Margin="4">
            <liquid:Tree.Nodes>
                <liquid:Node ID="0" Title="Root" Icon="images/folder.png" IconExpanded="images/folderOpen.png">
                    <liquid:Node.Nodes>
                        <liquid:Node ID="1" Title="Folder 1" Icon="images/folder.png" IconExpanded="images/folderOpen.png">
                            <liquid:Node.Nodes>
                                <liquid:Node ID="10" Title="File 1.doc" Icon="images/doc.png" />
                                <liquid:Node ID="11" Title="File 2.doc" Icon="images/doc.png" />
                            </liquid:Node.Nodes>
                        </liquid:Node>
                        <liquid:Node ID="2" Title="Folder 2" Icon="images/folder.png" IconExpanded="images/folderOpen.png">
                            <liquid:Node.Nodes>
                                <liquid:Node ID="20" Title="File 3.doc" Icon="images/doc.png" />
                                <liquid:Node ID="21" Title="File 4.doc" Icon="images/doc.png" />
                                <liquid:Node ID="21" Title="File 5.doc" Icon="images/doc.png" />
                            </liquid:Node.Nodes>
                        </liquid:Node>
                    </liquid:Node.Nodes>
                </liquid:Node>
            </liquid:Tree.Nodes>
        </liquid:Tree>
    </Grid>
</UserControl>


In the XAML we define 2 folder nodes which contain several child document nodes. The important attributes in the XAML are EnableDragAndDrop="true" and Drop="Tree_Drop".  The first ensures dragging and dropping is enabled and the second is the name of an event handler we have declared in the C# code behind file which allows you specify where the node is positioned or whether the Drop operation should be cancelled.

using System.Windows.Controls;

using Liquid;

namespace TreeViewDragAndDrop
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }

        private void Tree_Drop(object sender, TreeEventArgs e)
        {
            e.DropAction = Tree.DropActions.InsertAfter;
        }
    }
}


In this event handler you can instruct the TreeView to insert the node before or after the node under the cursor.  Or if you like the node can be appended as a child of the node under the cursor, either as the first or last child.  It is also possible to cancel the drop operation by setting e.Cancel = true, this allows for a lot of flexibility in your Silverlight apps.

 
 
Latest Games
Zombie Escape
Apr 19, 2016
Plays: 2,513

Zombie Escape ScreenshotDrive fast before the crazy mutant zombies get you!

6 Ratings/4.1 Average
Car Parking
Jan 16, 2016
Plays: 2,380

Car Parking ScreenshotGuide the car to its parking space in this fun Car Parking game.

1 Rating/5 Average
Trash It
Jan 11, 2016
Plays: 2,286

Trash It ScreenshotAim for the Trash Can and get the various items of Trash in the bin.

4 Ratings/5 Average
Sky Fly
Jan 11, 2016
Plays: 2,435

Sky Fly ScreenshotFly your plane in this colorful vertical scrolling shoot-em-up. Blast the bad guys and collect any bonus's they leave behind.

1 Rating/5 Average
Professor Snappy
Jan 11, 2016
Plays: 1,969

Professor Snappy ScreenshotPop as many bubbles as possible in this fun and colorful bubble popping game. The levels start off easy enough but gradually get harder!

1 Rating/5 Average
Monster Match Saga
Jan 10, 2016
Plays: 2,294

Monster Match Saga ScreenshotHere we have a bunch of monsters that need to be matched up. Look out for the bomb and spinning monsters that will cause special damage!

3 Ratings/4.6 Average
Fly Bird Fly
Jan 10, 2016
Plays: 2,122

Fly Bird Fly ScreenshotGuide your friendly Bird through the maze of pipes and other obstacles collecting the Stars in this cool arcade game inspired by the legendary Flappy Bird.

1 Rating/5 Average
Life In One
Jan 10, 2016
Plays: 2,297

Life In One ScreenshotYou are stranded on an Alien planet. Your goal is to build a space rocket and escape. Start by building units to create power and mine the metal patches. Build defenses to defend your base from the advancing Aliens and Zombies!

2 Ratings/3 Average
X Pool
Jan 02, 2016
Plays: 2,914

X Pool ScreenshotPlay Pool against the computer or battle against your friends in the online mode!

3 Ratings/3 Average
Fruit Slicer
Jan 02, 2016
Plays: 2,010

Fruit Slicer ScreenshotSlice the fruit that is thrown up onto the screen. Slice the fruit into multiple pieces for maximum points!

1 Rating/5 Average