Oku*_*ott 3 wpf xaml routed-events visual-studio-2015
我尝试在现有项目的用户控件中创建路由事件,但收到错误消息 The event 'foo' is not a RoutedEvent.
为了确保我没有疯,我制作了一个示例项目,其中仅包含有问题的代码(一个最小、完整和可验证的示例”)。
只有我在示例项目中没有收到任何错误消息。但这是完全相同的代码!
即使有错误消息,项目也会编译并且 RoutedEvent 工作!
我尝试清理项目、重建、重新启动 VS 和我的 PC,但无论我做什么,此错误消息仍然存在。
我相信这只是一个 IDE 问题。
我使用的是 Microsoft Visual Studio Professional 2015 版本 14.0.25431.01 更新 3
namespace Okuma_FFP
{
using System.Windows;
using System.Windows.Controls;
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
RaiseEvent(new RoutedEventArgs(fooEvent, this));
}
public static readonly RoutedEvent fooEvent = EventManager.RegisterRoutedEvent(
"foo", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(UserControl1));
// Provide CLR accessors for the event
public event RoutedEventHandler foo
{
add { AddHandler(fooEvent, value); }
remove { RemoveHandler(fooEvent, value); }
}
}
}
Run Code Online (Sandbox Code Playgroud)
<UserControl x:Class="Okuma_FFP.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Okuma_FFP"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Triggers>
<EventTrigger RoutedEvent="local:UserControl1.foo">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
To="Blue"
Duration="0:0:5"
Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</UserControl.Triggers>
<Grid> </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
这是一个IDE错误。
可能重复:即使项目生成,Visual Studio 也会显示错误
我从这个答案中得到了一个提示,并确保在清洁解决方案和构建之间退出 VS。
- 删除所有 obj、bin、release 和 debug 文件夹
- 删除
Project_Folder\.vs\Project_Name\v14\.suo- 在 Visual Studio 中打开解决方案
- 清洁溶液
- 退出 Visual Studio
- 再次打开解决方案
- 建造,建造,建造……
- 确认它已修复并去喝咖啡
| 归档时间: |
|
| 查看次数: |
1813 次 |
| 最近记录: |