Friday, August 31, 2007

Mouse wheel support in Silverlight

Silverlight currently doesn't include support for mouse wheel events, but a couple of projects I've done recently required it. Since Silverlight has pretty decent browser integration I was able to just hook into the browser's mouse wheel events and leverage that. The code is primarily based off of Adomas's work which can be found at adomas.org/javascript-mouse-wheel but had to make a couple of modifications for OS X support.

A simple example of it working:


The source code for this can be found here.

The more complex example of it is my Virtual Earth map.

The source contains code for both Silverlight 1.0 and Silverlight 1.1 integration. Originally I had the 1.1 support all nicely packaged into a single C# code file which was nice, but I ran into some limitations of the browser interop that turned out prevented me from supporting Safari fully. I've been told the interop blockers have been removed which is great, but hopefully mouse wheel support gets into the runtime before I move to the next bits :)

Labels: ,

I finally got around to checking my Virtual Earth app on Safari and surprise! it doesn't work.

Turns out the technique I'm using to inject Javascript into the page from managed code isn't compatible with Safari which is breaking the mouse wheel scrolling and something is busted with the back button support. I'm quite bummed about the mouse wheel stuff because I had a cool sample ready to go on how to use it, but the workaround is ugly. Hopefully I'll get it going again soon.

Probably the biggest lesson I've gotten out of this project is that anytime I rely on browser functionality- from layout to javascript, Murphy's Law comes into full effect, productivity drops to nil and frustration boils over.

In the meantime, the app works fine on Firefox on OS X so I'd suggest using that instead. But I'm not giving up on Safari!

Labels: , , ,