In this blog describes the use of setter,
style and trigger property in the WPF.
XAML Code
<Window
x:Class="Example02.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="DarkBlue" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="20" Color="DarkRed" Direction="50" Opacity="0.9"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="Background" Value="Orange"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Button Style="{StaticResource ButtonStyle}" Width="100" Height="50" Content="Click me first" Grid.Row="0"/>
<Button Style="{StaticResource ButtonStyle}" Width="150" Height="30" Content="Click me second" Grid.Row="1"/>
<Button Style="{StaticResource ButtonStyle}" Width="200" Height="40" Content="Click me third" Grid.Row="2"/>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="DarkBlue" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="20" Color="DarkRed" Direction="50" Opacity="0.9"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="Background" Value="Orange"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Button Style="{StaticResource ButtonStyle}" Width="100" Height="50" Content="Click me first" Grid.Row="0"/>
<Button Style="{StaticResource ButtonStyle}" Width="150" Height="30" Content="Click me second" Grid.Row="1"/>
<Button Style="{StaticResource ButtonStyle}" Width="200" Height="40" Content="Click me third" Grid.Row="2"/>
</Grid>
</Window>
Join the conversation! Your thoughts help the community grow.