MouseWheel doesn't work if there are nested TreeViews
Posted: 30 May 2021, 11:12
Hi
I have a TreeView which in a TreeViewItem contains a TreeView, which is why the MouseWheel is not working.
To the TreeView I added a Behavior that handles the PreviewMouseWheel()
The handler goes up all the ScrollViewers and determines which ScrollViewer to redirect the MouseWheel message to.
It doesn't work quite right. Scrolling works even if any Popup elements are active.
I tried to call the MouseWheel message on the Parent of the ScrollViewer, but then the scrolling stops working
I have a TreeView which in a TreeViewItem contains a TreeView, which is why the MouseWheel is not working.
To the TreeView I added a Behavior that handles the PreviewMouseWheel()
Code: Select all
void MouseWheelBehavior::OnPreviewMouseWheel(BaseComponent* sender, const MouseWheelEventArgs& e)
{
auto is_skip_scrollviewer = [](Noesis::ScrollViewer* viewer, int wheel) -> bool {
if ((wheel > 0 && viewer->GetVerticalOffset() == 0) ||
(wheel < 0 && viewer->GetVerticalOffset() >= viewer->GetExtentHeight() - viewer->GetViewportHeight())) {
return true;
}
return false;
};
auto scroll = Gui::Helper::GetParentRecursive<Noesis::ScrollViewer>((Noesis::Visual*)e.source);
while (scroll) {
if (is_skip_scrollviewer(scroll, e.wheelRotation)) {
scroll = Gui::Helper::GetParentRecursive<Noesis::ScrollViewer>((Noesis::Visual*)scroll);
}
else {
e.handled = true;
MouseWheelEventArgs eventArg{ scroll, UIElement::MouseWheelEvent, e.wheelRotation };
scroll->RaiseEvent(eventArg);
break;
}
}
}It doesn't work quite right. Scrolling works even if any Popup elements are active.
I tried to call the MouseWheel message on the Parent of the ScrollViewer, but then the scrolling stops working
Code: Select all
MouseWheelEventArgs eventArg{ scroll, UIElement::MouseWheelEvent, e.wheelRotation };
scroll->GetUIParent()->RaiseEvent(eventArg);