HorizontalScroll 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package HorizontalScroll --version 1.0.2                
NuGet\Install-Package HorizontalScroll -Version 1.0.2                
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="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HorizontalScroll --version 1.0.2                
#r "nuget: HorizontalScroll, 1.0.2"                
#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=1.0.2

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

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
    1. Enabling Application-Wide
  2. Events

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

Behaviors

HorizontalScrollBehavior can be attached to any ScrollViewer control, and adds support for scrolling horizontally by tilting the mouse wheel or by holding the Shift key while scrolling up or down.

You can attach it to a specific ScrollViewer entirely in XAML:

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

    
</ScrollViewer>

Scrollable WPF controls like ListBox, ListView, TreeView, DataGrid, etc. are implemented using a ScrollViewer, so you can use HorizontalScrollBehavior to add support for them as well. While you could use a ControlTemplate to accomplish that, a better way is to use an EventSetter to attach it in the Loaded event:

<ListBox>
    <ListBox.Resources>
        <Style TargetType="{x:Type ScrollViewer}">
            <EventSetter Event="Loaded" Handler="ScrollViewer_Loaded" />
        </Style>
    </ListBox.Resources>
</ListBox>
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 HorizontalScrollBehavior( /* magnitude: 0.5 | magnitudeBinding: new Binding() */ ));
}

Enabling Application-Wide Support

The previous example showed how to attach HorizontalScrollBehavior to a ListBox's internal ScrollViewer, but that approach can also be used for an entire window or application. The exact same code as the previous example will work just fine, but if you want to make your own ScrollViewer style later on you may want one with a key so you can inherit from it:

<ListBox>
    <ListBox.Resources>

        
        <Style x:Key="AttachScrollBehaviorStyle" TargetType="{x:Type ScrollViewer}">
            <EventSetter Event="Loaded" Handler="ScrollViewer_Loaded" />
        </Style>

        
        <Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource AttachScrollBehaviorStyle}" />

    </ListBox.Resources>
</ListBox>
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e)
{
    // Tip: You can set the Magnitude property in the HorizontalScrollBehavior constructor.
    Interaction
        .GetBehaviors((ScrollViewer)sender)
        .Add(new HorizontalScrollBehavior(/* 0.5 | new Binding() | new MultiBinding() */));
}

Events

HorizontalScroll adds two attached events for all subclasses of UIElement:

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

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