Nested ScrollViewers swallow Mousewheel events
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
When you have a control using a `ScrollViewer` inside of another `ScrollViewer`, the inner `ScrollViewer` will swallow the mouse wheel events preventing scrolling of the outer `ScrollViewer`.
### Reproduction Steps
- Create a new WPF project
- Use the following xaml for the `MainWindow`
```XAML
```
### Expected behavior
When using the mousewheel to scroll over the content I can scroll over blue, red and green without problems.
### Actual behavior
When the mouse is over the red area (inner `ScrollViewer`) the scrolling does not work with mouse wheel.
### Regression?
This did never work.
### Known Workarounds
I use a derived `ScrollViewer` in these scenarios where I do not swallow if no scrollbar is present.
```CSHARP
using System.Windows;
using System.Windows.Input;
namespace WpfApp
{
public class MyScrollViewer : System.Windows.Controls.ScrollViewer
{
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
if (ComputedVerticalScrollBarVisibility == Visibility.Visible)
{
base.OnMouseWheel(e);
}
}
}
}
```
Of course this only works if `VerticalScrollBarVisibility` is set to `Auto` on the inner `ScrollViewer`.
### Impact
This influences the User experience when mouse wheel scrolling does suddenly not proceed or does not start when hovering over certain elements of the UI.
### Configuration
This is not specific to any configuration.
### Other information
I would suggest to implement changes so that a `ScrollViewer` does not swallow the event when it does not scroll.
I think checking for `ComputedVerticalScrollBarVisibility ` before setting
[Handled to true](https://github.com/dotnet/wpf/blob/a40faea13a537cb03b49ea5968574afa4c0c6f6b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs#L1125), could be a good solution (equivalent to the `ScrollViewer` implementation in the workaround).
This also effects key events for scrolling. But the mouse wheel is probably the most annoying part of this. I never saw complaints about the keys. But the MouseWheel issue has been a source of UI complaints for many years.
Contributor guide
Assessment
This issue has not been assessed yet.