Andrzej
Andrzej

Reputation: 571

MouseMove works, MouseDown does not. WPF XAML

I made Button in Xaml. I would like to fire MouseDown event:

    MouseDown="Button_MouseDown_1"

I implemented this method in codeBehind, but it doesn't work. But if I implement this method:

    MouseMove="Button_MouseMove_1"

Implementation works. Where is the problem ?

Seba.

Upvotes: 2

Views: 1440

Answers (1)

Alternator
Alternator

Reputation: 164

The Button element itself is handling the mouse down event before your event handler gets called - meaning your event handler wont get called.

More than likely what you're actually wanting to implement is the Click event though (e.g.):

Click="button1_Click"

This will respond to the button getting clicked by the mouse or if it has focus and enter is pressed etc...

But if you really do need to specifically implement a handler for the mousedown event on the button you can use the PreviewMouseDown event which your handler will be notified of.

MSDN: Routed Events Overview can give more detail of how routed events work.

Upvotes: 1

Related Questions