DataBinding in Treeview with Drag and Drop Features in Silverlight

No.of Views1508
Bookmarked0 times
Downloads 
Votes0
By  usamawahabkhan   On  27 Nov 2010 00:11:03
Tag : Silver Light and XAML , Data Binding
In this article, i will show you how to implement databinding to treeview with drag and drop features in silverlight.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article, i will show you how to implement databinding to treeview with drag and drop features in silverlight.The silverlight is now days is used in most web application. because this look and feel is great.But there are some limitation in implementation vise.Through this article, i will explain how we could implement drag and drop features within treeview,when we are bind data to treeview.

Final Output

Image Loading

Implementation

 Step 1

Let's create a silverlight project using visual studio 2010.

Image Loading

Step 2

Now we have to add class to write code to get the data from database and implement other necessary functions.my class name is "Layer.cs", if you want to you can choice any name for this class. 

Image Loading

The Layer.cs class will like following,

Layer.cs 

Image Loading

Step 3

Now navigate to Main.axml design surface and add treeview control and made design like followings,

 

Image Loading

Note:As you see in above screen shot, i have added a StackPanel within the two TreeViewDragDropTarget.More about TreeViewDragDropTarget here. Now add TreeView and TreeviewTemplate within the TreeViewDragDropTarget as like following. 

Image Loading

This is first treeview have a checkbox and label in order to display Layer object properties.I need to add one more Treeview to display images with drag and drop features. 

Image Loading

Now design is ready, next navigate to code behind and write code.

 

Image Loading

Now here is important points we have to handle in our code, when you are bind images to control in silverlight, you can't do this. because silverlight image binding using ImageSource to bind images source in to control.So Microsoft made easy , we can do use the Converter to do this easily.

Note:Here more about Converter in Sillverlight

http://msdn.microsoft.com/en-us/library/98bbex99%28VS.95%29.aspx

http://msdn.microsoft.com/en-us/library/cc645047%28VS.95%29.aspx

Now we write simple code to Convert Image to Bind Control, 

Image Loading

That's all we have done, let's run the code and check or uncheck the checkbox and see how is working, then you able to drag and drop the left side or right side portion to within bi-direction.

Download Sample Project

Download source files -4740 kb

Summary

Through this article, you have learned In this article,how to implement databinding to treeview with drag and drop features in silverlight.I hope this helps.

 
Sign Up to vote for this article
 
About Author
 
usamawahabkhan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Pakistan
Joined date-06 May 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    For any data driven application with declarative data binding, with in XAML ,this brand new feature is the significant in many ways.Personally I remember most of the time i used to skip XAML way of binding as it lacked debugging feature.Now with Silverlight 5 my previous approach will surely take a back seat and will allow me to consider both ways equally.
    Published Date : 15/Apr/2011
    About Relational/Hierarchical data and CRUD operation against them using RIA.So its time to add some more functionality to the SOI application .
    Published Date : 12/Mar/2011
    How do we create Silverlight application that follows MVVM Web Application Pattern and Performing CRUD operations in Silverlight Data Grid?
    Published Date : 17/Jun/2010
    ADO.Net Classes is Absent in Silverlight That why some time Developer get confused How Retrieve Data in Silvrelight Application? Silverlight Provide ServiceModel Class You Thought this Class You can Call Web services
    Published Date : 11/Jun/2010
    In this article, I have tried to demonstrate this with simple steps. What all we are going to do is Download content of XML file as string using WebClient class,Parse XML file using LINQ to XML and Bind parsed result as item source of Data Grid.
    Published Date : 28/Apr/2011
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top