views:

3897

answers:

2

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.

+4  A: 

You have to supply the Type as well, so:

<EventTrigger RoutedEvent="Mouse.MouseEnter"></EventTrigger>
Razzie
+1  A: 

Fully-qualify the event name:

<EventTrigger RoutedEvent="Border.MouseEnter">

</EventTrigger>

HTH, Kent

Kent Boogaart