c# – WPF/XAML animation using own event – Education Career Blog

I’ve used WPF for quite some time now, but I’ve never looked serious into animation. I’m trying to achieve the following, but until now, not successful.

I have a class called “Property”. This class has the ability to fire an event:

public class Property
    // ...

    public event System.Windows.RoutedEventHandler Attract;

    // ...

The properties are shown on the screen. Sometimes I need to attract the user’s attention to a certain property. I want to fire the “Attract” event on the property. Then, from XAML start an animation.

I would expect something like this:

<Storyboard x:Key="blinkingAnimation">
    <DoubleAnimation From="0" To="1" Duration="0:0:5" RepeatBehavior="3x" AutoReverse="True" Storyboard.TargetProperty="(UIElement.Opacity)" />

<DataTemplate x:Key="PropertyTemplate" DataType="{x:Type GridViewColumn}">
            <EventTrigger RoutedEvent="Attract">
                    <BeginStoryboard Storyboard="{StaticResource blinkingAnimation}"/>

Is this the proper way to do it? At runtime, the compiler fails to resolve the “Attract” event. What am I doing wrong?


That’s not the proper way to declare a routed event. See msdn (http://msdn.microsoft.com/en-us/library/system.windows.routedevent.aspx) for reference.

Leave a Comment