WPF EventTrigger Error Message "Attached event field missing"

I'm building a .NET 4 WPF Application with RoutedEvents that i implemented by myself and then use them in xaml to execute Storyboards. The Program compile without errors and works as intended, but ReSharper tells me that my solution contains an error. In the following codesegement it underlines the RoutedEvent and with mouse over it shows the error message "Attached event field missing"

error1.png
But the application works fine and even the EventTrigger works as it should. What do i have to do to get rid of this error? For a better understanding here to code a had written for this events.

The code behind the xaml file (only the code fragments used by the RoutedEvent)
namespace TestProcessAnalyzingTool
{
  public partial class WindowTestSettings : Window
  {
    public static readonly RoutedEvent MessageColorChangedBubbleEvent =
      EventManager.RegisterRoutedEvent ( "MessageColorChanged", RoutingStrategy.Bubble, typeof ( RoutedEventHandler ), typeof ( WindowTestSettings ) );

    public event RoutedEventHandler MessageColorChanged
    {
      add { AddHandler ( MessageColorChangedBubbleEvent, value ); }
      remove { AddHandler ( MessageColorChangedBubbleEvent, value ); }
    }

    public void SetMessage ( string message = null, Brush messageForgroundBrush = null, Color? messageForgroundColor = null )
    {
      if ( messageForgroundBrush != null || messageForgroundColor != null )
      {
        labelResult.Foreground = messageForgroundBrush ?? new SolidColorBrush ( (Color) messageForgroundColor );
        RoutedEventArgs bubbleArgs = new RoutedEventArgs ( MessageColorChangedBubbleEvent );
        RaiseEvent ( bubbleArgs );
      }
      labelResult.Content = message ?? string.Empty;
    }
  }
}

The XAML Window
<Window x:Class="TestProcessAnalyzingTool.WindowTestSettings"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:TestProcessAnalyzingTool="clr-namespace:TestProcessAnalyzingTool"
        Title="Einstellungen []" Width="500" Height="121" Icon="/TestProcessAnalyzingTool;component/Resources/Toolbox.png">
  <Grid>
    <Label Name="labelResult" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="12,0,124,12">
      <Label.Background>
        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
          <GradientStop Color="Transparent" Offset="0" />
          <GradientStop Color="Transparent" Offset="0.5" />
          <GradientStop Color="Transparent" Offset="1" />
        </LinearGradientBrush>
      </Label.Background>
    </Label>
  </Grid>
  <Window.Triggers>
    <EventTrigger RoutedEvent="TestProcessAnalyzingTool:WindowTestSettings.MessageColorChanged">
      <BeginStoryboard>
        <Storyboard>
          <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="labelResult" Storyboard.TargetProperty="(Label.Background).(LinearGradientBrush.GradientStops)[1].Color">
            <SplineColorKeyFrame KeyTime="00:00:00" Value="Transparent" />
            <SplineColorKeyFrame KeyTime="00:00:00.15" Value="#445AA0FF" />
            <SplineColorKeyFrame KeyTime="00:00:00.3" Value="Transparent" />
            <SplineColorKeyFrame KeyTime="00:00:00.45" Value="#445AA0FF" />
            <SplineColorKeyFrame KeyTime="00:00:00.6" Value="Transparent" />
            <SplineColorKeyFrame KeyTime="00:00:00.75" Value="#445AA0FF" />
            <SplineColorKeyFrame KeyTime="00:00:00.9" Value="Transparent" />
          </ColorAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Window.Triggers>
</Window>


The purpose of this code is that if the SetMessage(...) Methode is called and either a Brush or a Color is set than the MessageColorChanged Event should raise. In the XAML-File I bind this event to a storyboard which flashes the background of a label. It just works fine only ReSharper 5.1.1 thinks it's an error (as you can see in the screenshot above). It's annoying to see the red-dot on the bottom-left corner of my solution with a rising number of errors because i have implemented events like this multiple times in different windows and user controls.

Am I doing something wrong while implementig the WPF events or is just ReSharper a little bit buggy with WPF events?

Thanks for any input,

Johannes

3 comments
Comment actions Permalink

Hello Johannes,

This looks like a bug in ReSharper. I've created a bug-report: http://youtrack.jetbrains.net/issue/RSRP-197953
and you're welcome to monitor its status. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I'm building a .NET 4 WPF Application with RoutedEvents that i
implemented by myself and then use them in xaml to execute
Storyboards. The Program compile without errors and works as intended,
but ReSharper tells me that my solution contains an error. In the
following codesegement it underlines the RoutedEvent and with mouse
over it shows the error message "Attached event field missing"

Image:error1.png But the application works fine and even the
EventTrigger works as it should. What do i have to do to get rid of
this error? For a better understanding here to code a had written for
this events.

|| *The code behind the xaml file (only the code fragments used by the
RoutedEvent)

  • ||

| namespace TestProcessAnalyzingTool
{
public partial class WindowTestSettings : Window
{
public static readonly RoutedEvent MessageColorChangedBubbleEvent
=
EventManager.RegisterRoutedEvent ( "MessageColorChanged",
RoutingStrategy.Bubble, typeof ( RoutedEventHandler ), typeof (
WindowTestSettings ) );
public event RoutedEventHandler MessageColorChanged
{
add { AddHandler ( MessageColorChangedBubbleEvent, value ); }
remove { AddHandler ( MessageColorChangedBubbleEvent, value ); }
}
public void SetMessage ( string message = null, Brush
messageForgroundBrush = null, Color? messageForgroundColor = null )
{
if ( messageForgroundBrush != null || messageForgroundColor !=
null )
{
labelResult.Foreground = messageForgroundBrush ?? new
SolidColorBrush ( (Color) messageForgroundColor );
RoutedEventArgs bubbleArgs = new RoutedEventArgs (
MessageColorChangedBubbleEvent );
RaiseEvent ( bubbleArgs );
}
labelResult.Content = message ?? string.Empty;
}
}
}
|
|| *The XAML Window

  • ||

| <Window x:Class="TestProcessAnalyzingTool.WindowTestSettings"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:TestProcessAnalyzingTool="clr-namespace:TestProcessAnalyzingTool
"
Title="Einstellungen []" Width="500" Height="121"
Icon="/TestProcessAnalyzingTool;component/Resources/Toolbox.png">
<Grid>
<Label Name="labelResult" HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" Margin="12,0,124,12">
<Label.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Transparent" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<GradientStop Color="Transparent" Offset="1" />
</LinearGradientBrush>
</Label.Background>
</Label>
</Grid>
<Window.Triggers>
<EventTrigger
RoutedEvent="TestProcessAnalyzingTool:WindowTestSettings.MessageColorC
hanged">
<BeginStoryboard>
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="labelResult"
Storyboard.TargetProperty="(Label.Background).(LinearGradientBrush.Gra
dientStops)[1].Color">
<SplineColorKeyFrame KeyTime="00:00:00"
Value="Transparent" />
<SplineColorKeyFrame KeyTime="00:00:00.15"
Value="#445AA0FF" />
<SplineColorKeyFrame KeyTime="00:00:00.3"
Value="Transparent" />
<SplineColorKeyFrame KeyTime="00:00:00.45"
Value="#445AA0FF" />
<SplineColorKeyFrame KeyTime="00:00:00.6"
Value="Transparent" />
<SplineColorKeyFrame KeyTime="00:00:00.75"
Value="#445AA0FF" />
<SplineColorKeyFrame KeyTime="00:00:00.9"
Value="Transparent" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
</Window>
|

The purpose of this code is that if the SetMessage(...) Methode is
called and either a Brush or a Color is set than the
MessageColorChanged Event should raise. In the XAML-File I bind this
event to a storyboard which flashes the background of a label. It just
works fine only ReSharper 5.1.1 thinks it's an error (as you can see
in the screenshot above). It's annoying to see the red-dot on the
bottom-left corner of my solution with a rising number of errors
because i have implemented events like this multiple times in
different windows and user controls.

Am I doing something wrong while implementig the WPF events or is just
ReSharper a little bit buggy with WPF events?

Thanks for any input,

Johannes

---
Original message URL:
http://devnet.jetbrains.net/message/5277664#5277664



0
Comment actions Permalink

Does it work if you rename the "MessageColorChangedBubbleEvent" field to "MessageColorChangedEvent"? All routed events in the framework have a field called "EventNameEvent", whereas you have a field called "EventNameBubbleEvent".

0
Comment actions Permalink

Hello Richard,

yes your workaround seems to be working. But it's still a bug in ReSharper because my custom names for events work fine, only ReSharper is marking them as error.

Thanks,
Johannes

0

Please sign in to leave a comment.