5

Possible Duplicate:
How to add a Blend Behavior in a Style Setter

when I use an interaction trigger in a style, I am getting the following error, 'triggers is not attachable element of type style'. Any explanation what this error actually means and how to solve it.

For reference take a look at MVVM Light toolkit's EventToCommand example.

In this particular case, I am using Timeline control from Infragistics which represents events as EventTitle and when the EventTitle is clicked, I would like to raise the command (Note that Timeline control doesn't define any event like EventTitleClicked). Currently I am able to achieve the functionality by using events and calling my ViewModel method from the code behind, instead I would like to invoke the command directly from 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" />
    ....
Community
  • 1
  • 1
skjagini
  • 3,142
  • 5
  • 34
  • 63

2 Answers2

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>
sobby01
  • 1,916
  • 1
  • 13
  • 22
-2
<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>
sobby01
  • 1,916
  • 1
  • 13
  • 22
  • 7
    This is beside the point, the asker wants to do it in a style, applying it to a discrete control is trivial. – H.B. Apr 22 '11 at 22:27