简体   繁体   中英

WPF/XAML animation using own event

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)" />
</Storyboard>

<DataTemplate x:Key="PropertyTemplate" DataType="{x:Type GridViewColumn}">
    <TextBox>
        <TextBox.Triggers>
            <EventTrigger RoutedEvent="Attract">
                <EventTrigger.Actions>
                    <BeginStoryboard Storyboard="{StaticResource blinkingAnimation}"/>
                </EventTrigger.Actions>
            </EventTrigger>
        </c:NumericTextBox.Triggers>
    </TextBox>
</DataTemplate>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM