SIGN UP MEMBER LOGIN:    
ARTICLE

Tree View Control in Silverlight 3

Posted by Diptimaya Patra Articles | XAML August 02, 2009
In this article we will explore about Tree View control in Silverlight 3.
Reader Level:
Download Files:
 

Introduction

In this article we will explore about Tree View control in Silverlight 3.

Crating Silverlight Project

Fire up Visual Studio 2008 and create a Silverlight Application. Name it as TreeViewSL3.

image1.gif

The TreeView control displays data in a hierarchical manner.

Open the solution in Expression Blend 3.

Go ahead and a Tree View control to your application.

I have changed the Background to Linear Brush.

To add TreeView Item to the Tree View, just right click on it and add TreeViewItem.

image2.gif

Add several, and if you want to add children of any parent then select the particular TreeViewItem and add another Treeview Item.

I have created the below hierarchy:

image3.gif

If you see the design view it will look similar to the following:

image4.gif

Here is the XAML code behind for the TreeView:

<controls:TreeView x:Name="MyTreeView" HorizontalAlignment="Left" Width="197" Margin="0,0,0,202">
                        <controls:TreeView.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="Gray" Offset="0"/>
                                                <GradientStop Color="White" Offset="1"/>
                                    </LinearGradientBrush>
                        </controls:TreeView.Background>
                        <controls:TreeViewItem Margin="0" Header="Item 1">
                                    <controls:TreeViewItem Margin="0" Header="Sub Item 1"/>
                        </controls:TreeViewItem>
                        <controls:TreeViewItem Margin="0" Header="Item 2">
                                    <controls:TreeViewItem Margin="0" Header="Sub Item 1"/>
                                    <controls:TreeViewItem Margin="0" Header="Sub Item 2"/>
                        </controls:TreeViewItem>
                        <controls:TreeViewItem Margin="0" Header="Item 3">
                                    <controls:TreeViewItem Margin="0" Header="Sub Item 1">
                                                <controls:TreeViewItem Margin="0" Header="Sub Item 1"/>
                                    </controls:TreeViewItem>
                        </controls:TreeViewItem>
  </controls:TreeView>

Now if you run the application you can expand or collapse a particular TreeViewItem.

image5.gif

This article is very basic to understand the Tree View Control in Silverlight 3. We will explore more on this in forth coming articles.

Enjoy Coding.

share this article :
post comment
 

how to add animation to tree nodes.
how to change the expand collapse triangle button

Posted by Nidhi Nov 18, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor