Frecklefoot
Frecklefoot

Reputation: 1692

Visual Studio gives error on valid XAML

I wrote a custom control in WPF XAML using Visual Studio 2015. I wrote a little test application for it and, once I got it working, copied it to another application. There I got errors in my XAML. In this code:

<Canvas.Triggers>
    <EventTrigger RoutedEvent="MouseEnter" SourceName="imgCenter">
        <BeginStoryboard Name="GlowAnimation">
            <Storyboard>
                <DoubleAnimation 
                    Storyboard.TargetName="cirHighlight"
                    Storyboard.TargetProperty="Opacity"
                    From="0"
                    To="1"
                    Duration="0:0:0.5" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
    ...

I get an error on MouseEnter. It appears red and mousing over it displays the message:

EventTrigger.RoutedEvent
Cannot resolve symbol 'MouseEnter'

I have several triggers, and all of them give me the red text and error message on the RoutedEvent.

That's strange, but even stranger is that it actually compiles and works: the triggers work and operate as expected. But it's really frustrating that they appear as errors in the editor. I'm new to animation in WPF and rely on the IDE to tell me if I'm doing something wrong. So for now, the IDE thinks I'm screwing up, but the framework executes it fine.

Any idea what's going on and how to resolve it?

EDIT

I forgot to mention that I'm using ReSharper. It appears this may be the source of the problem.

EDIT

ReSharper is definitely the problem. I loaded my solution into Visual Studio on a workstation that doesn't have ReSharper and, sure enough, no errors.

Upvotes: 1

Views: 716

Answers (2)

Frecklefoot
Frecklefoot

Reputation: 1692

I went to the other posts as @maulik and @FreeMan suggested. The solutions there didn't work, but it got me to look at something closer. Clicking the lightbulb next to the offending line (is that ReShaper or Visual Studio that does that?), it suggested I change my formatting from:

<EventTrigger RoutedEvent="MouseEnter" SourceName="imgCenter">

To this:

<EventTrigger SourceName="imgCenter">
    <EventTrigger.RoutedEvent>MouseEnter</EventTrigger.RoutedEvent>

Even though they are only syntactically different, the second version doesn't show an error. I'm not sure I really like this solution--I may have to just uninstall and reinstall ReSharper to keep the same syntax--but it did get rid of the error.

Upvotes: 2

maulik kansara
maulik kansara

Reputation: 1107

Try below:

<EventTrigger RoutedEvent="MouseEnter" SourceName="imgCenter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
 <DoubleAnimation 
                Storyboard.TargetName="cirHighlight"
                Storyboard.TargetProperty="Opacity"
                From="0"
                To="1"
                Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>

Upvotes: 2

Related Questions