I’m trying to capture the mousewheel event on a Silverlight 4 DataGrid. The problem is that whenever the mousewheel event is handled by the DataGrid the MouseWheel event does not fire. But when the DataGrid is at the top and I try to scroll upwards I get the MouseWheel event and the same thing at the bottom – i.e. the event is fired when the DataGrid does not handle the MouseWheel event itself.
I’ve also tried to capture the mousewheel event on the vertical ScrollBar (the Silverlight DataGrid does not use a ScrollViewer)
- How can I prevent the scrolling?
- If I don’t prevent the scrolling – how can I capture the event in all scenarios?
-
Can I capture MouseWheel events even though I haven’t focused the DataGrid yet (the event does not fire and the scrolling does not work before focusing the DataGrid)? Or should I use the following events:
HtmlPage.Window.AttachEvent(“DOMMouseScroll”, OnMouseWheel);
HtmlPage.Window.AttachEvent(“onmousewheel”, OnMouseWheel);
HtmlPage.Document.AttachEvent(“onmousewheel”, OnMouseWheel);
Any help appreciated. Thank you.
to prevent scrolling you could derive from the DataGrid and override OnMouseWheel.
If you want to get ALL events on a UIElement you can do this with the AddHandler method where you can set a flag to get even the handled events. Here’s an example:
I hope this helps.
BR,
TJ