Tuesday, June 10, 2008

[Silverlight B2] No more "MouseLeftButtonDown" event on Button?

Whee! More problems!

I have been using the "MouseLeftButtonDown" event to register all of my events that may pertain to a click. I've been doing this in practice because some of my objects differentiate between clicking down and clicking up [like for drag/drop]... so I just always extended this into my other object's event handlers... like buttons.

So before I had something like this:

[Button x:Name="Group" FontFamily="Arial" Content="Group" MouseLeftButtonDown="Group_MouseLeftButtonDown"]

But when Beta 2.0 dropped, that event no longer seemed to fire or was not getting registered correctly... I'm not actually sure since I couldn't find any documentation in the Breaking Changes page. I imagine it is tied to the changes made to event bubbling in 2.0.

To fix this I simply needed to change my buttons to use Click:

[Button x:Name="Group" FontFamily="Arial" Content="Group" Click="Group_Click" Margin="2"]

I still think that as an application designer we should be able to apply different event handlers to both the mousedown and mouseup events on a button, so maybe a solution will present itself in time. For now though, it was acceptable for me to simple switch to registering the Click event.

I just wanted to blog this as being an issue for me, in case anyone else ran into the same thing - or had some more info.

NOTE
Through the intellisense on VS2008, it came to my attention that:
  • Click is a RoutedEventHandler
  • MouseLeftButtonDown/Up events are MouseButtonEventHandler(s)
  • Each have their own respective argument types
I didn't realize there was a difference between mouseup/down and click... and perhaps this could point to part of the problem I was having.

NOTE
This blog gives a decent explanation of the bubbling changes that have occurred.

.

No comments: