I wrote about Silverlight and the mouse(wheel) before and the responses are pretty good. One question that stuck to my brain and has been asked in forums is how to actually have controls like the ListBox respond to the MouseWheel event.
First some code
After decorating a ComboBox like this:
It is pretty easy to add this code:
But as you will notice when testing this code the ComboBox only responds to the wheel when it is collapsed. I tried adding the decorator to the ItemsPanel but that froze the entire Silverlight application. I see no solution for that.
On to the ListBox
To make a control that uses the ScrollViewer to scroll its content you need to access the ScrollViewer that is in the template of the control. For some reason the GetTemplateChild method was made protected so the only way to get it you need to sub class the control and add a little code:
This ListBox now has a ScrollViewer property that can be used in code like this:
I have tried to encapsulate this behavior into the ListBox class itself but the problem I ran into is that to make it easy to use I need a way of manipulating the template of the ListBox to add the decorator. It is easy to replace an entire template of a control but I wanted to add the decorator to the existing template in runtime. That is not possible as far as I can see.
I updated the download with this code so you can test and try for yourself.
It looks like a hack. And it is. To get this working we need the Silverlight Base Control developers to help us out on this.