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

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

 Subscribe to Articles

Styles in WPF

Posted By:Syed Shakeer Hussain       Posted Date: January 16, 2011    Points: 75    Category: WPF    URL: http://www.dotnetspark.com  

This article shows you how to apply styles a control in WPF

Apply Styles to a control.

Lets you have created no.of button controls on a Form.It may be be difficult to set styles to every contrl.To rescue this type of problem,we can set Styles to all controls by setting element.

Lets create buttons as follows

Style attribute:-

1)TargerType:This is used to set a Styles to a WPF controls as follows

TagetType="Button"  TargetType="Label"  TargetType="ListBoxItem"

eg:- <Style TargetType="Button"> Style>

Setting Style Properties to a control:This can be done by using property and value attributes

eg:<Setter Property="FontWeight" Value="Bold">Setter>

Styles have to set in <Window.Resources> Window.Resources> Element.

<Window x:Class="WpfComboBox.ButtonStyles"



Title="ButtonStyles" Height="300" Width="500">


<Style TargetType="Button">

<Setter Property="FontWeight" Value="Bold">Setter>

<Setter Property="Foreground" Value="Red">Setter>

<Setter Property="Background" Value="LightSteelBlue">Setter>

<Setter Property="BorderBrush" Value="Pink">Setter>





<StackPanel Orientation="Horizontal" Background="Bisque" >

<Button Content="Submit" Width="90" Height="35" Margin="20">Button>

<Button Content="Cancel" Width="90" Height="35">Button>





When you run the Program the Applied styles to a Button control looks as below image.

Thanks for reading my article!


 Subscribe to Articles


Further Readings:


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