Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventTrigger bind to event from DataContext

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>
like image 222
bkovacic Avatar asked Oct 09 '22 01:10

bkovacic


1 Answers

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.

like image 97
H.B. Avatar answered Oct 13 '22 10:10

H.B.