我已经为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'
我已将事件触发器中的上述路由事件更改为:
xaml解析器无法识别Mouse.DragOver,Mouse.DragLeave,Mouse.Drop,它会突出显示。 有什么想法吗?
答案 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>