Change Value of Properties using Triggers in WPF Application

Updated on     Kisan Patel

This post will show you how to change the value of properties using triggers in WPF application?

You can change the look and feel of controls in WPF application using the PropertyTriggers trigger.

You can assign a trigger by using the IsMouseOver or IsKeyboardFocused property.


<Window x:Class="WPFStackPanelDemo.MainWindow"
   Title="MainWindow" Height="350" Width="525">
            <Style x:Key="ChangeStyle" TargetType="{x:Type TextBox}">
               <Setter Property="Background" Value="Red"/>
               <Setter Property="FontSize" Value="12"/>
                   <Trigger Property="IsMouseOver" Value="True">
                       <Setter Property="Background" Value="Blue"/>
                       <Setter Property="FontSize" Value="20"/>
          <TextBox Width="200" Height="40" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 10, 0, 0"
Style="{StaticResource ChangeStyle}" />
          <TextBox Width="250" Height="40" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0, 100, 0, 0"
Style="{StaticResource ChangeStyle}" />

When you run the application, you can see below output:



Leave a Reply