Creating an event trigger
Till now, we have seen property triggers and data triggers, which work based on comparing a property to a value. In this recipe, we will learn about event triggers which fire when a routed event occurs.
Getting ready
Inside your Visual Studio IDE, create a new project called CH06.EventTriggerDemo
, based on the WPF application template.
How to do it...
Follow these steps to create a simple event trigger on a TextBlock
control:
- Open the
MainWindow.xaml
and add the followingTextBlock
inside theGrid
:
<TextBlock Text="Hover here" FontSize="30" Opacity="0.2" HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock.Style> </TextBlock.Style> </TextBlock>
- Add the following style, containing
EventTrigger
, to theTextBlock.Style
attribute:
<Style TargetType="TextBlock"> <Style.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <EventTrigger...