First create dictionary as I explained here.
In my case I've created TriggersDictionary.xaml, so my main window XAML looks like this:
<Window x:Class="PlayingWithResource.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"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source= "TriggersDictionary.xaml"> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <Rectangle Style="{StaticResource styleWithTrigger}"></Rectangle> </Grid> </Window>
My style (TriggersDictionary.xaml)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="styleWithTrigger" TargetType="Rectangle"> <Setter Property="Fill" Value="LightGreen" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Fill" Value="Red" /> </Trigger> </Style.Triggers> </Style> </ResourceDictionary>
Here you can see property - this is event which will be executed as well as target type (in my case rectangle)
Example project you can download from here, and this article I wrote using this page.
----
2014-06-16 Update Properties which are supported for trigger, for rectangle, for example you can see here.