HorizontalScroll 2.0.0

dotnet add package HorizontalScroll --version 2.0.0                
NuGet\Install-Package HorizontalScroll -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HorizontalScroll" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HorizontalScroll --version 2.0.0                
#r "nuget: HorizontalScroll, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HorizontalScroll as a Cake Addin
#addin nuget:?package=HorizontalScroll&version=2.0.0

// Install HorizontalScroll as a Cake Tool
#tool nuget:?package=HorizontalScroll&version=2.0.0                

horizontalscroll-banner-color-outline

NuGet package for .NET 6+ that adds attached events for handling inputs from tiltable scroll wheels and provides an easy way to improve scrolling behavior in your application. It's lightweight, easy to use, and provides documentation through intellisense.

Requires the Microsoft.Xaml.Behaviors.Wpf nuget package.

NuGet Version
HorizontalScroll NuGet Status

Features

  • New events for handling tilt wheel inputs:
    • HorizontalScroll.PreviewMouseWheelTilt
    • HorizontalScroll.MouseWheelTilt
  • New behavior for ScrollViewer controls:
    • Scrolls horizontally when tilting the mouse wheel
    • Shift+ScrollWheel scrolls horizontally
    • Scrolling sensitivity can be set or data-bound

Usage

  1. HorizontalScrollBehavior
  2. Events

Note: No xmlns declarations are required to use HorizontalScroll in XAML.

Behaviors

HorizontalScrollBehavior

HorizontalScrollBehavior is a ScrollViewer behavior that adds support for scrolling horizontally by tilting the mouse wheel or by holding the Shift key while scrolling up or down.
It can be attached to a specific ScrollViewer in the usual way through XAML, or to all ScrollViewers in a scope (including the ones inside of other controls, like a ListBox or DataGrid) with a target-typed style and an EventSetter.

Attaching to a specific ScrollViewer:

<ScrollViewer xmlns:i="http://schemas.microsoft.com/xaml/behaviors">
    <i:Interaction.Behaviors>
        <HorizontalScrollBehavior />
    </i:Interaction.Behaviors>
</ScrollViewer>

To attach it to all of the ScrollViewer controls in a scope, create a target-typed style resource and an EventSetter for the Loaded event:

<Application.Resources>
    <Style x:Key="EnableHorizontalScrollStyle" TargetType="{x:Type ScrollViewer}">
        <EventSetter Event="Loaded" Handler="ScrollViewer_Loaded" />
    </Style>
</Application.Resources>

And attach the behavior in the code-behind:

private void ScrollViewer_Loaded(object sender, RoutedEventArgs e)
{
    // Tip: You can set the Magnitude property (to a value or binding) in the HorizontalScrollBehavior constructor.
    Interaction
        .GetBehaviors((ScrollViewer)sender)
        .Add(new HScroll.HorizontalScrollBehavior( /* magnitude: 0.5 | magnitudeBinding: new Binding() */ ));
}

You can change the scrolling sensitivity with the Magnitude DependencyProperty, and/or disable the Shift+ScrollWheel input binding with the EnableShiftScroll DependencyProperty.

AttachHorizontalScrollBehavior

In situations where you want to apply a HorizontalScrollBehavior to a specific control's internal ScrollViewer without affecting list items, or in cases where the ScrollViewer isn't available when the behavior would normally be attached (such as when setting ListView.View), you can use AttachHorizontalScrollBehavior to attach it on the attached control's Loaded event. It works by searching the descendants and/or ancestors of the control for a ScrollViewer, and attaches a HorizontalScrollBehavior to it.

<ListView xmlns:i="http://schemas.microsoft.com/xaml/behaviors">
    <i:Interaction.Behaviors>
        <AttachHorizontalScrollBehavior />
    </i:Interaction.Behaviors>
    <ListView.View>
        <GridView>
            <GridViewColumn />
        </GridView>
    </ListView.View>
</ListView>

You can fine-tune the search behavior for finding the ScrollViewer with the SearchMode & SearchDepth properties.
The search mode determines whether ancestors and/or descendants are searched, and in what order.
The search depth determines how many layers of ancestor/descendant controls can be searched.

Events

HorizontalScroll adds two attached events for all subclasses of UIElement:

Event Handler Type EventArgs Type
HorizontalScroll.PreviewMouseWheelTilt MouseWheelEventHandler MouseWheelEventArgs
HorizontalScroll.MouseWheelTilt MouseWheelEventHandler MouseWheelEventArgs

You can get the horizontal delta value from MouseWheelEventArgs.Delta.
A positive delta means the wheel was tilted right, negative values mean it was tilted left.

Usually the delta value is -120 (left) or 120 (right), but this should not be relied upon as MSDN says other values are allowed in order to perform smaller scrolling increments.

Example

<TextBox
    x:Name="MyTextBox"
    HorizontalScroll.PreviewMouseWheelTilt="MyTextBox_PreviewMouseWheelTilt"
    HorizontalScroll.MouseWheelTilt="MyTextBox_PreviewMouseWheelTilt" />
private void TextBox_PreviewMouseWheelTilt(object sender, MouseWheelEventArgs e)
{
    // do something...
    // setting e.Handled to true here will prevent the MouseWheelTilt event from firing.
}
private void TextBox_MouseWheelTilt(object sender, MouseWheelEventArgs e)
{
    // do something...
}
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 297 12/11/2023
1.0.3 130 12/10/2023
1.0.2 134 12/8/2023
1.0.1 149 12/6/2023
1.0.0 138 12/5/2023
0.1.1 127 12/5/2023
0.1.0 134 12/5/2023
0.0.0 150 12/5/2023

[d80b40f] fix UpdateNugetPackages.yaml not firing due to condition