Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 605 |  Welcome, Guest!   Register  Login
Home > Articles > Silverlight > How to display hierarchical items in TreeView and How to display a Button on the page in Silverlight?

How to display hierarchical items in TreeView and How to display a Button on the page in Silverlight?

Article posted by SheoNarayan on 12/26/2011 | Views: 1359 | Category: Silverlight | Level: Beginner | Points: 250 red flag


In this article, we would learn the usage of SilverLight UI Controls i.e.TreeView and Button.

TreeView

TreeView control of Silverlight facilitates the display the hierarchical items in Tree structure.

How to display hierarchical items in TreeView?

To display hierarchical items in Tree view, we can follow this approach.

This article is the continuation of my last article in Silverlight controls series, read last article here.

Get 500+ ASP.NET web development Tips & Tricks and ASP.NET Online training here.

Code

<sdk:TreeView x:Name="TreeView1">

<sdk:TreeViewItem Header="Science">

<sdk:TreeViewItem Header="Physics" />

<sdk:TreeViewItem Header="Chemistry" />

<sdk:TreeViewItem Header="Math" />

<sdk:TreeViewItem Header="Biology" />

</sdk:TreeViewItem>

<sdk:TreeViewItem Header="Arts">

<sdk:TreeViewItem Header="History" />

<sdk:TreeViewItem Header="Political Science" />

</sdk:TreeViewItem>

</sdk:TreeView>

As seen in the above code, we have a TreeView control which displays the items.

Output
 
 

Button

Button control is mostly used to submit user data or perform some activity (or action) based on click of the button. This is one of the most frequently used controls in the Silverlight application.

How to display a button on the page in Silverlight.

 

Code

<Button Content="Submit" x:Name="btnTest" Canvas.Top="15" Canvas.Left="50"/>

<Button x:Name="btnTestAgain" Canvas.Top="55" Canvas.Left="50" Width="150" Height="30">

<Button.Content>

<Canvas>

<Ellipse Width="125" Height="25" Canvas.Left="-60" Canvas.Top="-13" Fill="Aqua" />

<TextBlock Text="Button Text" Canvas.Left="-30" Canvas.Top="-10"/>

</Canvas>

</Button.Content>

</Button>

Note that Button control doesn’t have a Text property but it has Content property that let us display any object as Button content, it can be text, an image or any other content.

In the above code snippet, first we have a Button control whose Content is specified as “Submit” text. In the other Button we have specified Button.Content as the Ellipse and TextBlock that displays the shape and Text as Button content.

Output
 
 

How to display Image as Button content?

In case we need to display an image as Button content, following is the way....

Code

<Button x:Name="btnTestAgain" Canvas.Top="55" Canvas.Left="50" Width="150" Height="130">

<Button.Content>

<Image Source="../Images/DotNetLogo.jpg"/>

</Button.Content>

</Button>

Here in the Button.Content is kept as Image that will display Image within the button content.

Output
 

Hope this article was useful. Thanks for reading, hope you liked it.

Keep a watch on forth coming articles on Silverlight. To read my series of articles,click here.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Sheo Narayan

Experience:8 year(s)
Home page:http://www.snarayan.com
Member since:Tuesday, July 08, 2008
Level:HonoraryPlatinum
Status: [Microsoft_MVP] [Administrator]
Biography:Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001.

Connect me on Facebook | Twitter | LinkedIn | Blog

>> Write Response - Respond to this post and get points
Related Posts

In this article, we are going to learn working with data in SilverLight.

In this article, we are going to learn about DataGrid in silverlight and its related properties.

In this article I will not be binding the controls with the data from Database. My example is a very simple example, like a hello world type of Example. In this article I am going to bind the individual controls from a property value. To follow my example you need Expression Blend.

A friend of mine, who is doing working on a GIS project, asked me, if I could get him a cool control that will show maps based on the Coordinates at ease without worrying about other map problems that GIS developers come across every day. So this triggered me to write something nice with the Map control from Telerik.

In this article we will look as how to invoke Silver light methods from javascript

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/27/2012 7:40:03 PM