jc_lvngstn
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?
Thanks,
JC
 
golgepapaz
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
sfernandez
Site Admin
Posts: 1918
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 1 guest