5
votes

I'm trying to accomplish something like this:

<DataTemplate.Triggers>
    <EventTrigger RoutedEvent="{Binding MyEvent}">
        <BeginStoryboard Storyboard="{StaticResource MyAnimation}" />
    </EventTrigger>
</DataTemplate.Triggers>

MyEvent is event from my DataContext.

This does not work because RoutedEvent can't be Binding expression. Any idea how to accomplish this? In fact, I need some mix of EventTrigger and DataTrigger...

Solution with Blend SDK:

<Interactivity:Interaction.Triggers>
    <Interactivity:EventTrigger SourceObject="{Binding}" EventName="MyEvent">
        <ei:ControlStoryboardAction ControlStoryboardOption="Play">
            <ei:ControlStoryboardAction.Storyboard>
                <Storyboard>
                    ....
                </Storyboard>
            </ei:ControlStoryboardAction.Storyboard>
        </ei:ControlStoryboardAction>
    </Interactivity:EventTrigger>
</Interactivity:Interaction.Triggers>
1
why trigger at all? can you not create a command, which starts your storyboard, and call that command's execute from wherever you want?user572559
Just for clarifying.. Do you want to add custom events that you'll be able to raise manually?Anatolii Gabuza
Yes, I have event in my ViewModel, which I raise manually.bkovacic

1 Answers

4
votes

Using the EventTriggers from Interactivity (Blend SDK) can trigger on any event on any object, the native ones only work for RoutedEvents which you normally only have on controls.