Skip to content

[API Proposal]: MouseHorizontalWheel and friends #11961

Open

Description

@miloush

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

  1. added
    API suggestion
    on Sep 22, 2026
  2. Roshaless commented on Sep 22, 2026

    @Roshaless

    A proposed alternative was to add IsHorizontalMouseWheel property to the MouseWheelEventArgs and not add any new separate events, which is the API in UWP.

    This alternative also seems quite good to me. Adding only an IsHorizontalMouseWheel property to MouseWheelEventArgs would avoid adding the separate MouseHorizontalWheel and PreviewMouseHorizontalWheel events, and it would also keep the handling in OnMouseWheel simple.

    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 existing OnMouseWheel method and only adds a property to distinguish horizontal scrolling.

    If we added a separate event, it would introduce something like:

    +     public static readonly RoutedEvent MouseHorizontalWheelEvent;
    +     public static void AddMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
    +     public static void RemoveMouseHorizontalWheelHandler(DependencyObject element, MouseWheelEventHandler handler);
    
    +     protected override void OnMouseHorizontalWheel(MouseWheelEventArgs e)
    +     {
    +         // Horizontal wheel handling
    +     }

    In contrast, with the IsHorizontalMouseWheel property, the same logic can stay in the existing OnMouseWheel path:

    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 ScrollViewer and TextBoxBase, adding handling for the IsHorizontalMouseWheel property 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 IsHorizontalMouseWheel property-based approach.

  3. miloush commented on Sep 22, 2026

    @miloush
    ContributorAuthor

    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.

  4. lindexi commented on Sep 22, 2026

    @lindexi
    Member

    @miloush Chances are this won't be a problem in practice anyway, since horizontal scrolling is still scrolling.

  5. lindexi commented on Sep 22, 2026

    @lindexi
    Member

    @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.

  6. miloush commented on Sep 22, 2026

    @miloush
    ContributorAuthor

    @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?

  7. h3xds1nz commented on Sep 22, 2026

    @h3xds1nz
    Member

    I strongly disagree with both of these alternative approaches, they're both breaking and behaviour changing.

    The proposal as-is serves its purpose well.

  8. lindexi commented on Sep 22, 2026

    @lindexi
    Member

    @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?

    For devs just getting into WPF, this is pretty confusing: why do you need MouseHorizontalWheelEvent for 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.

  9. miloush commented on Sep 22, 2026

    @miloush
    ContributorAuthor

    @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 has CanHorizontallyScroll), and evolution of hardware. If you want pan-scrolling, the manipulation events are better suited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API suggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions