I have an outer listbox with a vertical scrollbar, and on each item I have a scrollviewer that might have a horizontal scrollbar. The problem is that when I use the mouse the event doesn't get to the outer listbox, so scrolling doesn't work. I have already set Focusable=false on the scrollviewers, but that just prevents them for handling keyboard events, not mouse events. How can I stop the inner scrollviewer from catching the mouse wheel event and allow it to bubble up to the outer listbox?
You might find some good examples here. It describes how to disable the mouse wheel in an ItemsControl
The problem is that the ListBox itself has a ScrollViewer that is swallowing up the mouse wheel events before they can get to the parent ScrollViewer that contains your ListBox.
You need to handle the preview mouse wheel events on the ListBox, and thus prevent them from tunnelling further down, while at the same time, raise a bubbling event to the parent ScrollViewer.
This worked for me:
private void ListBoxThatNowScrolls_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
e2.RoutedEvent = ListBox.MouseWheelEvent;
e2.Source = e.Source;
ListBoxThatNowScrolls.RaiseEvent(e2);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With