WPF EventTriggers - 无法将属性“RoutedEvent”中的字符串“DragOver”转换为Visual Studio 2008中“System.Windows.RoutedEvent”类型的对象

时间:2017-07-04 11:32:46

标签: c# wpf xaml visual-studio-2008 eventtrigger

我已经为WPF按钮实现了一些触发器,如下所示:

   <ControlTemplate.Triggers>
        <EventTrigger RoutedEvent="DragOver">
            <BeginStoryboard Storyboard="{StaticResource swap}"/>
            <BeginStoryboard Storyboard="{StaticResource fadein}"/>
        </EventTrigger>

        <EventTrigger RoutedEvent="DragLeave">
            <BeginStoryboard Storyboard="{StaticResource reset}"/>
            <BeginStoryboard Storyboard="{StaticResource fadeout}"/>
        </EventTrigger>

        <EventTrigger RoutedEvent="Drop">
            <BeginStoryboard Storyboard="{StaticResource reset}"/>
            <BeginStoryboard Storyboard="{StaticResource fadeout}"/>
        </EventTrigger>
    </ControlTemplate.Triggers>

这在Visual Studio 2015中完美运行,但在Visual Studio 2008中,它会被抛出错误:

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

我已将事件触发器中的上述路由事件更改为:

  • RoutedEvent =“DragOver” - &gt; RoutedEvent = “Mouse.DragOver”
  • RoutedEvent =“DragLeave” - &gt; RoutedEvent = “Mouse.DragLeave”
  • RoutedEvent =“Drop” - &gt; RoutedEvent = “Mouse.Drop”

xaml解析器无法识别Mouse.DragOver,Mouse.DragLeave,Mouse.Drop,它会突出显示。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。我需要在路由事件之前使用Button和下面的句点。现在正在努力:

   <ControlTemplate.Triggers>
        <EventTrigger RoutedEvent="Button.DragOver">
            <BeginStoryboard Storyboard="{StaticResource swap}"/>
            <BeginStoryboard Storyboard="{StaticResource fadein}"/>
        </EventTrigger>

        <EventTrigger RoutedEvent="Button.DragLeave">
            <BeginStoryboard Storyboard="{StaticResource reset}"/>
            <BeginStoryboard Storyboard="{StaticResource fadeout}"/>
        </EventTrigger>

        <EventTrigger RoutedEvent="Button.Drop">
            <BeginStoryboard Storyboard="{StaticResource reset}"/>
            <BeginStoryboard Storyboard="{StaticResource fadeout}"/>
        </EventTrigger>
    </ControlTemplate.Triggers>