Silverlight Button MouseLeftButtonUp/Down Event

Last few days, I have been trying to use a Button as a drag and drop object in Silverlight 4, but the MouseLeftButtonUp and MouseLeftButtonDown event just won’t fire up no matter how I click on it. After some search, I found out that MouseLeftButtonUp and MouseLeftButtonDown event in Button is handle by Click event thus it won’t trigger MouseLeftButtonUp and MouseLeftButtonDown anymore.

One solution for this is to create an inherited Button class and override MouseLeftButtonUp and MouseLeftButtonDown event by setting Handled to false so that it won’t handle by Click event. While the other solution is to use other UIElement control instead of Button.

But I’m lazy to create a class just for this purpose and I need a Button control. After some search on MSDN, I found out that I can prevent Click event to handle MouseLeftButtonUp and MouseLeftButtonDown event by setting button’s ClickMode to Hover which was by default is Press. It’s work! With just a single line or a property set, I can enable back MouseLeftButtonUp and MouseLeftButtonDown event for button now.

Source: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.onmouseleftbuttondown.aspx

by Ooi Keng Siang via Ooiks’s Blog