WPF EventTriggers - Cannot convert string 'MouseEnter' in attribute 'RoutedEvent' to object of type 'System.Windows.RoutedEvent'

EightyOne Unite picture EightyOne Unite · Mar 10, 2009 · Viewed 11.2k times · Source

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

<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 on Border since it is defined in UIElement but I'm still getting

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

as soon as i run the application.

Any help would be hugely appreciated.

Answer

Razzie picture Razzie · Mar 10, 2009

You have to supply the Type as well, so:

<EventTrigger RoutedEvent="Mouse.MouseEnter"></EventTrigger>