Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wpf

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>
like image 500
AXG1010 Avatar asked Sep 11 '25 00:09

AXG1010


1 Answers

You can use PreviewMouseDown and PreviewMouseUp instead

like image 199
Omri Btian Avatar answered Sep 13 '25 13:09

Omri Btian