.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Apply Styles In Silverlight Application

Posted By:Diptimaya Patra       Posted Date: April 04, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Apply Styles In Silverlight Application. In this article we will see how can we write simple styles for any control and use it effectively.
 

Introduction

In this article we will see how can we write simple styles for any control and use it effectively.

Crating Silverlight Project

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

style1.gif

Open MainPage.xaml in design mode. In xaml code behind, you can see by default a grid is added to the User Control.

To make it simple I am going to put the styles inside the Grid, otherwise we can use User Control also.

Inside Grid tag type
style2.gif

You guessed it right; we can use User Control Resources also. But for the time being we wil stick with Grid.Resources.

Inside Grid.Resources insert a Style tag.


  


To make it simple we will be setting a Style for TextBlock. So go ahead and properties to the Style tag.

Name the Style and set the TargetType to TextBlock.

 

Now we will add a Setter. Setter is nothing but to set a specific property of the target control type to a value.

Suppose we want to change the FontSize of the TextBlock to value 32. So we need to write as follows:


Add a TextBlock to the Grid and change the Style property.



See this is as simple as that. Now Press F5 and you can see the output as the Style is applied to the TextBlock.

style3.gif

Now we will change the ForeGround Color to Red. Add another Setter tag and add the Property and Value.



style4.gif

Now that you know how to add Style a control in xaml code behind, play with other Properties and other Controls.

Enjoy Coding.
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend