HorizontalScroll 1.0.3
See the version list below for details.
dotnet add package HorizontalScroll --version 1.0.3
NuGet\Install-Package HorizontalScroll -Version 1.0.3
<PackageReference Include="HorizontalScroll" Version="1.0.3" />
paket add HorizontalScroll --version 1.0.3
#r "nuget: HorizontalScroll, 1.0.3"
// Install HorizontalScroll as a Cake Addin #addin nuget:?package=HorizontalScroll&version=1.0.3 // Install HorizontalScroll as a Cake Tool #tool nuget:?package=HorizontalScroll&version=1.0.3
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 |
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
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows7.0
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.77)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.