Page 1 of 1

Buttons and OnMouseButtonDown - firing events.

Posted: 05 Oct 2013, 23:03
by jc_lvngstn
It seems like Buttons do not fire the OnMouseButtonDown event, while Textblocks and labels do. Is this by design?
Thanks,
JC

Re: Buttons and OnMouseButtonDown - firing events.

Posted: 06 Oct 2013, 19:07
by golgepapaz
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.

Re: Buttons and OnMouseButtonDown - firing events.

Posted: 07 Oct 2013, 14:14
by sfernandez
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.