5

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

当我在样式中使用交互触发器时,我收到以下错误,“触发器不是样式类型的可附加元素”。任何解释此错误的实际含义以及如何解决它。

作为参考,请查看 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" />
    ....
4

2 回答 2

2
<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>
于 2011-04-22T20:30:40.150 回答
-3
<TextBox x:Name="EditableControlTextBox" Loaded="RoomTextBox_Loaded">
         <interactivity:Interaction.Triggers>
              <interactivity:EventTrigger EventName="LostFocus">
                     <!--<cmd:EventToCommand Command="{Binding MyCommand}" />-->
              </interactivity:EventTrigger>
          </interactivity:Interaction.Triggers>
</TextBox>
于 2011-04-22T21:08:40.053 回答