Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 906
EightyOne Unite Avatar asked Mar 10 '09 13:03

EightyOne Unite


2 Answers

You have to supply the Type as well, so:

<EventTrigger RoutedEvent="Mouse.MouseEnter"></EventTrigger>
like image 144
Razzie Avatar answered Sep 27 '22 21:09

Razzie


Fully-qualify the event name:

<EventTrigger RoutedEvent="Border.MouseEnter">

</EventTrigger>
like image 37
Kent Boogaart Avatar answered Sep 27 '22 20:09

Kent Boogaart