WPF EventTriggers - cannot convert the string "MouseEnter" to the attribute "RoutedEvent" for an object of type "System.Windows.RoutedEvent"

I cannot get event triggers to work. A simplified example of what I'm doing below is -

<Window x:Name="win" x:Class="EventTriggers.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.Resources> <ControlTemplate x:Key="buttonT"> <Border Background="#333"> <TextBlock Text="{Binding}" HorizontalAlignment="Stretch" Foreground="White"/> <Border.Triggers> <EventTrigger RoutedEvent="MouseEnter"> </EventTrigger> </Border.Triggers> </Border> </ControlTemplate> <DataTemplate x:Key="lbt"> <Button Template="{StaticResource buttonT}" Click="Button_Click"></Button> </DataTemplate> </Window.Resources> <ListBox ItemsSource="{Binding ElementName=win,Path=col}" ItemTemplate="{StaticResource lbt}"> </ListBox> 

I know there is a MouseEnter event at the border, as it is defined in a UIElement , but I still get

Cannot convert string 'MouseEnter' to attribute 'RoutedEvent' for type object 'System.Windows.RoutedEvent'

as soon as I launched the application.

Any help would be greatly appreciated.

+4
source share
2 answers

You must also specify a Type, therefore:

 <EventTrigger RoutedEvent="Mouse.MouseEnter"></EventTrigger> 
+12
source

Fully-qualify event name:

 <EventTrigger RoutedEvent="Border.MouseEnter"> </EventTrigger> 
+5
source

All Articles