MouseWheel doesn't work if there are nested TreeViews
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);
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: MouseWheel doesn't work if there are nested TreeViews
Does the inner TreeView need a ScrollViewer or is it fully fit inside the item?
Because you can use a different template for those inner TreeViews without the ScrollViewer:
This way only the outer TreeView will have a ScrollViewer and mouse wheel will work just fine.
Because you can use a different template for those inner TreeViews without the ScrollViewer:
Code: Select all
<ControlTemplate x:Key="InnerTreeView" TargetType="TreeView">
<ItemsPresenter />
</ControlTemplate>
Re: MouseWheel doesn't work if there are nested TreeViews
Yes, I don't need internal ScrolViewers right now and this solution works.
But further scrolling may be required.
But further scrolling may be required.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: MouseWheel doesn't work if there are nested TreeViews
If you have nested ScrollViewers and mouse is over inner one, it will handle the mouse events before they reach the outer scroll viewer. So this is the expected behavior and you should design your UI with that in mind.Yes, I don't need internal ScrolViewers right now and this solution works.
You can scroll a ScrollViewer control manually by using the public functions: LineUp, LineDown, PageUp, PageDown, ScrollToTop, ScrollToBottom, ScrollToVerticalOffset...But further scrolling may be required.
I don't know if that is what you mean.
Who is online
Users browsing this forum: No registered users and 8 guests