Skip Navigation LinksHome / Tips / View Tip

Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?

+ Add to SilverlightShow Favorites
4 comments   /   posted by Martin Mihaylov on Nov 28, 2008
(12 votes)
Categories: General , Controls and UI

Have you ever noticed that the MouseLeftButtonDown and MouseLeftButtonUp events are not fired when a Silverlight button is clicked? The reason for this is that the button handles these two events itself by overriding the OnMouseLeftButtonDown  and the OnMouseLeftButtonUp  handlers. In the OnMouseLeftButtonDown  override, the Click event is raised and the MouseLeftButtonDown event is marked as handled so it couldn't bubble in the visual tree. The OnMouseLeftButtonUp  override also marks the MouseLeftButtonUp  as handled.

This thing can be changed using the ClickMode property of the Button control. It has the following values - Hover, Press, Release. The default one is Pressed and we have already explained it. When we have ClickMode set to Release, the Click event will be raised in the OnMouseLeftButtonUp override and the MouseLeftButtonDown and MouseLeftButtonUp events will be handled inside the button again. If we set the ClickMode to Hover, the Click event will be raised with the MouseEnter event and we will also be able to use the mouse button events.

That's it!

Share


Comments

Comments RSS RSS
  • RE: Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?  

    posted by Tim on Dec 30, 2008 17:16

    This worked great, better than making my own button class that derives from Button

  • RE: Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?  

    posted by Praveen on Feb 18, 2010 09:17
    Thanks for the tip
  • RE: Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?  

    posted by wuxy on Mar 31, 2010 12:12
    thanks
  • RE: Tip: How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?  

    posted by agui on Aug 18, 2010 04:40
    Thanks. That confuse me for a long time.

Add Comment

 
 

   
  
  
   
Please add 6 and 3 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)