AXG1010
AXG1010

Reputation: 1962

How to use Interaction Trigger on button with MouseUp and MouseDown events in XAML?

I have a button that needs to execute two separate commands (one to start something and one to stop it). After doing some research the System.Windows.Interactivity.dll seemed to provide an easy way to accomplish this. But it doesn't work with the left mouse button (it does work if I use an event like MouseDoubleClick or MouseRightButtonDown, but not MouseDown, MouseUp, or MouseRightButtonDown)...it seems as if the button consumes the event itself and the interaction.trigger never sees it. I provided a snippet of my XAML below, what can I do to get around this behavior?

<Button Content="DoStuff">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDown">
            <i:InvokeCommandAction Command="{Binding StartCommand}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="MouseUp">
            <i:InvokeCommandAction Command="{Binding StopCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

Upvotes: 4

Views: 8210

Answers (2)

Omri Btian
Omri Btian

Reputation: 6547

You can use PreviewMouseDown and PreviewMouseUp instead

Upvotes: 8

eran otzap
eran otzap

Reputation: 12533

mouseleftbuttondown , mouseleftbuttonup

Upvotes: 0

Related Questions