WPF 事件触发器 - 无法将属性 'MouseEnter' 中的字符串 'RoutedEvent' 转换为 'System.Windows.RoutedEvent' 类型的对象

标签 wpf eventtrigger

我无法让任何事件触发器工作。我正在做的事情的一个简化示例如下 -

<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>

我知道有一个 MouseEnter Border 上的事件,因为它是在 UIElement 中定义的但我仍然得到

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



只要我运行应用程序。

任何帮助将不胜感激。

最佳答案

您还必须提供类型,因此:

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

关于WPF 事件触发器 - 无法将属性 'MouseEnter' 中的字符串 'RoutedEvent' 转换为 'System.Windows.RoutedEvent' 类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/630239/

相关文章:

wpf - 以编程方式将 Datagrid 行显示在 WPF、MVVM 中

wpf - 重新启动 WPF Storyboard

c# - 旋转和打印正方形

silverlight - SL4/MVVM : Handle MouseDragElementBehavior. VM 中带有 void Foo() 的拖动事件

c# - 使用框架的 WPF 的 MVVM Light Toolkit NavigationService 实现

javascript - 停止触发器函数在Jquery中运行多次

jquery - 如何在单击鼠标左键时触发上下文菜单?

jquery - 如何通过 .change 触发器传递 html 元素引用

xaml - Windows Phone 8 中 ListPicker 的 selectionChanged 之前的交互触发

wpf 字典绑定(bind),其中 key=variable