I have a usercontrol that has a scrollviewer, then a bunch of child controls like text boxes, radio buttons, and listboxes, etc inside of it. I can use the mouse wheel to scroll the parent scrollviewer until my mouse lands inside a listbox then, the mouse wheel events start going to the listbox. is there any way to have the listbox send those events back up to the parent control? removing the listbox from within side the parent control like this question suggests (Mouse wheel not working when over ScrollViewer's child controls) isnt a solution.
I have tried
void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
}
but that didnt work either.
Thanks
I followed Amanduh's approach to solve the same problem I had with multiple datagrids in a scrollviewer but in WPF:
A modified Simon Fox's solution if the original doesn't work:
As Simon said, it's the ScrollViewer in the standard ListBox template that's catching the event. To bypass it you can provide your own template.
And the implementation for NoWheelScrollViewer is pretty simple.
Then, whenever you want a listbox to not handle the mouse wheel.
A simple solution which worked for me is to override the inner control template to remove the scroll viewer (whichever required) like this
For example I have a structure like this
ListView (a)
ListView (b)
I wanted to bubble the mouse wheel scroll of (b) to (a), however wanted to keep the mouse wheel scroll of (c) available. I simply overridden the Template of (b) like this. This allowed me to bubble contents of (b) except (c) to (a). Also, I can still scroll the contents of (c). If i want to remove even for (c) then i have to repeat the same step.
I was trying to adapt Simon Fox's answer for a DataGrid. I found the the template hid my headers, and I never got the mouseLeave event by doing it in C#. This is ultimately what worked for me:
This can be accomplished via attached behaviors.
http://josheinstein.com/blog/index.php/2010/08/wpf-nested-scrollviewer-listbox-scrolling/
Edit: Here is the linked solution:
Where the i namespace is from Blend: