Skip to content

Fix for 2923: Ignore vertical scroll inside TabControl header. - #2924

Merged
Keboo merged 6 commits into
MaterialDesignInXAML:masterfrom
nicolaihenriksen:fix2923
Nov 3, 2022
Merged

Fix for 2923: Ignore vertical scroll inside TabControl header.#2924
Keboo merged 6 commits into
MaterialDesignInXAML:masterfrom
nicolaihenriksen:fix2923

Conversation

@nicolaihenriksen

@nicolaihenriksen nicolaihenriksen commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

Fix for #2923

This PR introduces ScrollViewerAssist.IgnoreVerticalScroll attached property which effectively allows a user to opt-in on disabling vertical scrolling in a ScrollViewer. It works by registering for the already handled MouseWheel event, and then bubbling a copy of that event on its parent element.

A ScrollViewer will by default - as far as I know - consume (handled=true) the MouseWheel event, even if there is nothing for that particular ScrollViewer to scroll in (i.e. all content is displayed and visible in the viewport). The problem in the issue mentioned above was that the TabControl uses a ScrollViewer inside its header to enable horizontal scrolling (if there is not enough room for the tabs I presume), but that ScrollViewer consumes the vertical MouseWheel events as well; effectively disabling scrolling all together when the mouse hovers the ScrollViewer.

In scenarios like these where you want "horizontal" scrolling only, you can apply the attached property mentioned above. You can argue that you could end up with double-scrolling if the nested ScrollViewer (and the outer ScrollViewer) actually CAN scroll vertically AND you apply this attached property. However I see that as a somewhat unlikely scenario... In those cases you should of course not use the attached property.

I applied the attached property on the ScrollViewer in the MaterialDesignTabControlBase style and also added a sample to the demo application to showcase that it still works with scrollable content inside of the tab control.

The issue mentions that there is also a problem with the expander, but I believe that was just an issue in the demo application which had a not needed ScrollViewer added to Expander.xaml.

There is already a MainScrollViewer in place which handles the scrolling, so there is no need for the additional ScrollViewer; in fact this is what was causing scrolling not to work correctly when hovering the expanders.
Changed to file scoped namespace.
Introduced attached property to effectively disable the vertical scroll on a ScrollViewer.
@nicolaihenriksen nicolaihenriksen changed the title Fix2923 Fix for 2923: Ignore vertical scroll inside TabControl header. Oct 28, 2022
Comment thread MaterialDesignThemes.Wpf/ScrollViewerAssist.cs Outdated
@Keboo
Keboo merged commit 7151ebd into MaterialDesignInXAML:master Nov 3, 2022
@Keboo Keboo added this to the 4.7.0 milestone Nov 3, 2022
@nicolaihenriksen
nicolaihenriksen deleted the fix2923 branch November 3, 2022 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants