WPF Interaction在Style中触发,以在View Model上调用命令

skj*_*ini 5 wpf xaml icommand

可能重复:
如何在样式设置器中添加混合行为

当我在样式中使用交互触发器时,我收到以下错误,'触发器不是类型样式的可附加元素'.任何解释这个错误实际意味着什么以及如何解决它.

有关参考,请参阅MVVM Light工具包的EventToCommand示例.

在这种特殊情况下,我使用来自Infragistics的Timeline控件,它将事件表示为EventTitle,当单击EventTitle时,我想提出命令(请注意,Timeline控件不会定义任何事件,如EventTitleClicked).目前我能够通过使用事件并从后面的代码调用我的ViewModel方法来实现功能,而不是直接从xaml调用命令.

<Style x:Key="EventTitleTopStyle" TargetType="igTl:EventTitle">
    <!-- The following is not working -->
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <!--<cmd:EventToCommand Command="{Binding MyCommand}" />-->
        </i:EventTrigger>
    </i:Interaction.Triggers>

   <!-- Using event setter instead to achieve the same -->
    <EventSetter Event="MouseLeftButtonDown" Handler="TopTitleMouseLeftButtonDown" />
    ....
Run Code Online (Sandbox Code Playgroud)

sob*_*y01 1

<interactivity:Interaction.Triggers>
     <interactivity:EventTrigger EventName="MouseDoubleClick">
          <behaviours:ExecuteCommandAction Command="{Binding Path=DataContext.YourCommand, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}}}" 
               CommandParameter="{Binding }"/>
     </interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
Run Code Online (Sandbox Code Playgroud)