.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 >> 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"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

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

<Window.Resources>

<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>

Style>

Window.Resources>

<Grid>

<StackPanel>

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

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

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

StackPanel>

StackPanel>

Grid>

Window>

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

Thanks for reading my article!

Shakeer


 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