I tried making a Routed Event in a user control of an existing project and I'm getting the error message The event 'foo' is not a RoutedEvent.
To make sure I wasn't crazy, I made an example project with just the offending code (a Minimal, Complete, and Verifiable example").
Only I don't get any error message in my example project. But it's the exact same code!
Even with the error message, the project compiles and the RoutedEvent works!
I tried cleaning the project, rebuilding, restarting VS and my PC, but no matter what I do this error message persists.
I beleive this is just an IDE issue.
I'm using Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 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); }
}
}
}
<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>
This is an IDE bug.
Possible duplicate: Visual Studio displaying errors even if projects build
I took a hint from this answer and made sure to exit VS in-between cleaning the solution and building.
- Delete all obj, bin, release, and debug folders
- Delete
Project_Folder\.vs\Project_Name\v14\.suo
- Open the solution in Visual Studio
- Clean Solution
- Exit Visual Studio
- Open the solution again
- Build, build, build...
- Confirm it's fixed and go get coffee