EventTrigger绑定到DataContext的事件

时间:2012-01-09 13:40:15

标签: c# wpf xaml data-binding

我正在努力完成这样的事情:

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

MyEvent是来自我的DataContext的事件。

这不起作用,因为RoutedEvent不能是Binding表达式。知道怎么做到这一点? 事实上,我需要一些EventTrigger和DataTrigger的混合......

使用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 个答案:

答案 0 :(得分:4)

使用InteractivityBlend SDK)中的EventTriggers可以触发任何对象上的任何事件,原生的仅适用于您通常只有控件的RoutedEvents