Styles have a set of properties; here I am going to place some of important and frequent used properties.
Setters: Sets the property values
Triggers: Change the style settings
Resources: Gets or Sets a collection of resources you can use
BasedOn: Creates a specialized style that inherits the settings of another style
TargetType: Gets or Sets the Control for which the style is intended
Let's have a basic example of this, shall we?
Copy and paste the below code in your window1.xaml
- <Window.Resources>
- <Style x:Key="wpfStyle1" TargetType="{x:Type TextBlock}">
- <Setter Property="FontFamily" Value="Verdana"/>
- <Setter Property="FontSize" Value="10"/>
- </Style>
- <Style x:Key="wpfStyle2" TargetType="{x:Type TextBlock}">
- <Setter Property="FontFamily" Value="Arial"/>
- <Setter Property="FontSize" Value="16"/>
- </Style>
- </Window.Resources>
- <Grid>
- <TextBlock Margin="26,41,39,0" Style="{StaticResource wpfStyle1}" Height="31" VerticalAlignment="Top">TextBlock with Style1</TextBlock>
- <TextBlock Margin="26,77,39,0" Height="32" VerticalAlignment="Top">TextBlock with no Style</TextBlock>
- <TextBlock Margin="26,113,67,88" Style="{StaticResource wpfStyle2}">TextBlock with Style2</TextBlock>
- </Grid>
The code seen above creates a Style in the <Window.Resources>. That Style targets elements of type TextBlock, and sets their FontFamily and FontSize properties. Notice that the Styles have keys named wpfStyle1, wpfStyle2. The Style property on each TextBlock is then explicitly set to reference that Style.
Conclusion
This article would help you understand the styles in WPF.

Wee GaryPosted Apr 26, 2022, 3:32 PM
This is really clear demonstration. Thanks
Debasis SahaPosted Jul 1, 2015, 12:44 AM
Thanks for the article..
RakeshPosted Jul 1, 2015, 12:20 AM
Good one sir
Gopi ChandPosted Jun 30, 2015, 11:22 PM
Great sir...
Santhakumar MunuswamyPosted Jun 30, 2015, 2:26 PM
Thanks for nice article sir.
Charwaka ThupiliPosted Jun 30, 2015, 10:10 AM
Inofrmative
Nilesh JadavPosted Jun 30, 2015, 9:54 AM
Thank you for sharing sir !
Vipul MalhotraPosted Jun 30, 2015, 7:56 AM
nice article
Rajeesh MenothPosted Jun 30, 2015, 7:44 AM
Nice one