Repository navigation
Description
Background and motivation
Currently WPF does not support horizontal scrolling out of the box. Most of the work had been done in the codebase but it was never publicly surfaced. As a result, ScrollViewer with horizontal scroll bar cannot be scrolled using touch pad.
This is a proposal to add HorizontalWheel events and members mirroring the [Vertical]Wheel ones.
The existing MouseWheelEventArgs is reused for both events.
Implementation PR is here: #11956
API Proposal
namespace System.Windows;
public class ContentElement
{
...
public static readonly RoutedEvent MouseWheelEvent;
+ public static readonly RoutedEvent MouseHorizontalWheelEvent;
public event MouseWheelEventHandler MouseWheel;
+ public event MouseWheelEventHandler MouseHorizontalWheel;
protected internal virtual void OnMouseWheel(MouseWheelEventArgs e);
+ protected internal virtual void OnMouseHorizontalWheel(MouseWheelEventArgs e)
...
public static readonly RoutedEvent PreviewMouseWheelEvent;
+ public static readonly RoutedEvent PreviewMouseHorizontalWheelEvent;
public event MouseWheelEventHandler PreviewMouseWheel;
+ public event MouseWheelEventHandler PreviewMouseHorizontalWheel
protected internal virtual void OnPreviewMouseWheel(MouseWheelEventArgs e);
+ protected internal virtual void OnPreviewMouseHorizontalWheel(MouseWheelEventArgs e)
...
}Same for System.Windows.UIElement and System.Windows.UIElement3D.
(UIElement has protected virtual only handlers)
namespace System.Windows.Input
public static class Mouse
{
...
public static readonly RoutedEvent MouseWheelEvent;
public static void AddMouseWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
public static void RemoveMouseWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
+ public static readonly RoutedEvent MouseHorizontalWheelEvent;
+ public static void AddMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
+ public static void RemoveMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
...
public static readonly RoutedEvent PreviewMouseWheelEvent;
public static void AddPreviewMouseWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
public static void RemovePreviewMouseWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
+ public static readonly RoutedEvent PreviewMouseHorizontalWheelEvent;
+ public static void AddPreviewMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
+ public static void RemovePreviewMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
...
}Overrides of the new members:
namespace System.Windows.Controls.Primitives;
public class TextBoxBase
{
+ protected override void OnMouseHorizontalWheel(MouseWheelEventArgs e)
} namespace System.Windows.Controls;
public class FlowDocumentScrollViewer
{
+ protected override void OnMouseHorizontalWheel(MouseWheelEventArgs e)
}
public class ScrollViewer
{
+ protected override void OnMouseHorizontalWheel(MouseWheelEventArgs e)
}API Usage
ScrollViewer, FlowDocumentScrollViewer and TextBox base start supporting horizontal scrolling without any additional user code required.
Custom handling
<Image MouseHorizontalWheel="OnImageHorizontalWheel" ... />private void OnImageHorizontalWheel(object sender, MouseWheelEventArgs e)
{
var delta = e.Delta;
...
}Alternative Designs
A proposed alternative was to add IsHorizontalMouseWheel property to the MouseWheelEventArgs and not add any new separate events, which is the API in UWP.
However, for WPF this would be a breaking change as existing code would start getting horizontal events and handling them as vertical.
Edit: HorizontalDelta was also proposed to lower the compatibility impact while utiliing the existing events. That still carries risks of breaking handlers that do not care about the delta value, or do not expect it to be zero.
Note that IScrollInfo already contains CanHorizontallyScroll and separate SetHorizontalOffset/SetVerticalOffset methods so any unification needs to be split by implementations into separate calls anyway. Separate events also correspond to separate WM_MOUSEWHEEL and WM_MOUSEHWEEL Windows messages.
Risks
This is mirroring existing events, and implementation is building on existing infrastructure that already has RawMouseActions.HorizontalWheelRotate, so existing applications should not be affected.
The only potential risk might be if users already workarounded the gap by handling WM_MOUSEHWEEL themselves and did not mark it as handled. The damage would be more or less scrolling than expected.
Activity
Roshaless commentedon Sep 22, 2026
This alternative also seems quite good to me. Adding only an
IsHorizontalMouseWheelproperty toMouseWheelEventArgswould avoid adding the separateMouseHorizontalWheelandPreviewMouseHorizontalWheelevents, and it would also keep the handling inOnMouseWheelsimple.The main difference is that the first approach introduces an extra event method, such as
OnMouseHorizontalWheel, which means a new event and a separate handling path. The second approach is simpler: it reuses the existingOnMouseWheelmethod and only adds a property to distinguish horizontal scrolling.If we added a separate event, it would introduce something like:
In contrast, with the
IsHorizontalMouseWheelproperty, the same logic can stay in the existingOnMouseWheelpath:public class MouseWheelEventArgs { // ...... + public bool IsHorizontalMouseWheel { get; } // ...... } private void OnMouseWheel(object sender, MouseWheelEventArgs e) { + if (e.IsHorizontalMouseWheel || Keyboard.Modifiers is ModifierKeys.Shift) { // HorizontalWheel } else { // VerticalWheel } }For existing
ScrollViewerandTextBoxBase, adding handling for theIsHorizontalMouseWheelproperty is not very difficult. This is also more in line with modern APIs. (Other modern frameworks all adopt either a DeltaX/DeltaY-like approach or an Orientation-like approach.)Also, I've updated the HorizontalWheelFeature.cs implementation, so you can try out the
IsHorizontalMouseWheelproperty-based approach.miloush commentedon Sep 22, 2026
It's not about built-in controls that you can update with the change as needed. It is about all other handlers and controls customers have written and that do not expect OnMouseWheel to be called/MouseWheel to be fired for horizontal scrolling.
lindexi commentedon Sep 22, 2026
@miloush Chances are this won't be a problem in practice anyway, since horizontal scrolling is still scrolling.
lindexi commentedon Sep 22, 2026
@miloush My other idea: give Delta a horizontal counterpart. Then a horizontal scroll still raises MouseWheelEvent, but with Delta = 0 (but HorizontalDelta = 100), so the impact on existing logic is minimal.
miloush commentedon Sep 22, 2026
@lindexi that is potentially better, though it doesn't help if the handler does not care about the delta value. What are your concerns with the separate events?
h3xds1nz commentedon Sep 22, 2026
I strongly disagree with both of these alternative approaches, they're both breaking and behaviour changing.
The proposal as-is serves its purpose well.
lindexi commentedon Sep 22, 2026
For devs just getting into WPF, this is pretty confusing: why do you need
MouseHorizontalWheelEventfor horizontal scrolling, but not for vertical? That's just going to sit there as a legacy gotcha. And for canvases that scroll in all directions, you end up hooking up two separate events — it really feels like a patch.miloush commentedon Sep 22, 2026
@h3xds1nz I still maintain these would be breaking changes, but since I haven't heard why @lindexi has another preference, I wanted to make sure I am not missing anything.
It is indeed unfortunate that diagonal scrolling is split into two events, but that corresponds to the windows messages, the current design of
IScrollInfo(which already hasCanHorizontallyScroll), and evolution of hardware. If you want pan-scrolling, the manipulation events are better suited.