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?
The mouse wheel event doesn't work correcty on a lisbox when it has scrollviewers inside
Asked Answered
Are you sure you're not handling the event somewhere and setting Handled = true ? MouseWheelEvent is a RoutedEvent so it should route/bubble nicely. Probably you'll need to show some XAML. –
Petronel
You might find some good answers on this question: https://mcmap.net/q/466098/-disable-mouse-wheel-on-itemscontrol-in-wpf/302677 –
Tusche
Thanks for the link Rachel, I defined a NoWheelScrollViewer as described there and it worked –
Lerma
@Rachel, it would be helpful if you could copy your comment into an answer and if ovatsus could mark this question as answered. –
Sprocket
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);
}
Thank you so much! I had a feeling something like this was happening. For my situation, this was the best solution. –
Brusquerie
You might find some good examples here. It describes how to disable the mouse wheel in an ItemsControl
© 2022 - 2024 — McMap. All rights reserved.