Topic Author
Posts: 34
Joined: 23 Sep 2013, 03:03

Buttons and OnMouseButtonDown - firing events.

05 Oct 2013, 23:03

It seems like Buttons do not fire the OnMouseButtonDown event, while Textblocks and labels do. Is this by design?
Posts: 43
Joined: 01 Aug 2013, 01:59

Re: Buttons and OnMouseButtonDown - firing events.

06 Oct 2013, 19:07

I believe the mousebuttondown events are converted OnClick events by the button control.
I use tunneling version of the events (PreviewMouseLeftButtonDown for example) in this case . Please read about Routed events and Tunneling&bubbling event.
User avatar
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: Buttons and OnMouseButtonDown - firing events.

07 Oct 2013, 14:14

As golgepapaz pointed, Button control handles MouseLeftButtonDown event to generate Click event. It is explained in the WPF documentation:
This implementation marks the MouseLeftButtonDown event as handled by setting the Handled property of the event data to true when ClickMode is not set to Hover. To respond to the MouseLeftButtonDown event, attach an event handler to the PreviewMouseLeftButtonDown event.
So you would need to attach to the PreviewMouseLeftButtonDown event if you want to be notified when user is trying to click the button.

Who is online

Users browsing this forum: No registered users and 8 guests