Use this code for different styles for different buttons or other
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" HorizontalAlignment="Left" VerticalAlignment="Top"> <Window.Resources> **<Style x:Key="a" TargetType="{x:Type TextBlock}"> <Setter Property="FontFamily" Value="Verdana" /> <Setter Property="FontSize" Value="50"/> <Setter Property="Background" Value="Indigo"/> </Style> <Style x:Key="b" TargetType="{x:Type TextBlock}"> <Setter Property="FontFamily" Value="Arial"/> <Setter Property="FontSize" Value="16"/> </Style> <Style x:Key="c" TargetType="{x:Type Button}"> <Setter Property="FontFamily" Value="TimesNewRoman" /> <Setter Property="FontSize" Value="50"/> <Setter Property="Background" Value="Green"/> </Style> </Window.Resources> <Grid> <TextBlock Margin="26,41,39,0" Style="{StaticResource a}" Height="100" VerticalAlignment="Top">TextBlock with Style1</TextBlock> <TextBlock Margin="26,77,39,0" Height="32" VerticalAlignment="Top">TextBlock with no Style</TextBlock> <TextBlock Margin="26,105,67,96" Style="{StaticResource b}">TextBlock with Style2</TextBlock> <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="26,170,-26,0"> <Button Style="{StaticResource c}"> <Bold >Styles</Bold></Button> <Button Style="{StaticResource c}">are</Button> <Button Style="{StaticResource c}">cool</Button> </StackPanel> </Grid>
here I declare a style for both textBlock and button. Use this ...
Sankar
source share