Vectorlight News

  • Chat App Converted to HTML and JQuery
    Sep 08, 2011

    Converted from Silverlight to HTML and Javascript/JQuery is the Vectorlight Chat App. Login using your Vectorlight password to chat using your username and avatar.

  • HTML5 iPhone,Android Big Guns Tower Defense
    Jul 02, 2011

    Big Guns has made the leap from Windows Phone 7 (XNA) to HTML5 so you can now play it on your iPhone, Android and other HTML5 compatible devices.

  • HTML5 Games - Word Poppers and Batty
    Jun 04, 2011

    As the take-up of HTML5 quickens (74% of users currently have a browser capable of HTML5 Canvas) we present two more games for both your browser and mobile.

  • Big Guns Tower Defense on Windows Phone 7
    May 06, 2011

    Coming soon to Windows Phone 7 is an XNA port of the popular Vectorlight tower defense game Super Tower Defense. Whilst retaining many of the graphical and gameplay features of the original Silverlight game.

  • Wakacube WP7 Update
    Apr 26, 2011

    Released to the Windows Phone 7 marketplace today is Version 1.1 of Wakacube the 3D physics game of skill. Included in the update are more levels (30 in total) and new mode Wakatime which generates random crate structures to keep players entertained long after the levels have been completed.

  • Home Page News

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.

Rate this: 

1 Star 2 Star 3 Star 4 Star 5 Star
18 Ratings / 3.1 Average

Tweets

Silverlight Controls

  • Rich TextBox

    Create and edit rich content with this slick and expandable Rich TextBox...

  • TreeView

    This easy to use TreeView comes with drag and drop, sorting, searching and much more...

  • Context Menu

    You too can have cool popup context menus in your Silverlight applications...

  • Resizable Dialog

    Draggable and resizable popup dialogs are what serious Silverlight developers need...

  • Spell Checker

    Real-time spell checking in Silverlight? We did it first here...