Search code examples
wpfxamlvisual-studio-2015routed-events

The event 'foo' is not a RoutedEvent


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!

Does anyone have any ideas what's going on?

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

IDE=VS2015Pro

UserControl1.xaml.cs

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); }
        }
    }
}

UserControl1.xaml

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

Solution

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

    1. Delete all obj, bin, release, and debug folders
    2. Delete Project_Folder\.vs\Project_Name\v14\.suo
    3. Open the solution in Visual Studio
    4. Clean Solution
    5. Exit Visual Studio
    6. Open the solution again
    7. Build, build, build...
    8. Confirm it's fixed and go get coffee