Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Interaction triggers in a Style to invoke commands on View Model [duplicate]

Tags:

wpf

xaml

icommand

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" />
    ....
like image 290
skjagini Avatar asked Nov 26 '22 12:11

skjagini


1 Answers

<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>
like image 140
sobby01 Avatar answered May 16 '23 07:05

sobby01