HorizontalScroll 1.0.0
See the version list below for details.
dotnet add package HorizontalScroll --version 1.0.0
NuGet\Install-Package HorizontalScroll -Version 1.0.0
<PackageReference Include="HorizontalScroll" Version="1.0.0" />
paket add HorizontalScroll --version 1.0.0
#r "nuget: HorizontalScroll, 1.0.0"
// Install HorizontalScroll as a Cake Addin #addin nuget:?package=HorizontalScroll&version=1.0.0 // Install HorizontalScroll as a Cake Tool #tool nuget:?package=HorizontalScroll&version=1.0.0
Adds better horizontal scrolling support to WPF, and some useful behaviors for improving ScrollViewer
.
NuGet | Version |
---|---|
HorizontalScroll |
Many newer high-end mice have scroll wheels that can be tilted left or right to scroll horizontally, but WPF doesn't provide any support for them. HorizontalScroll provides attached events to receive these messages on a per-control basis, just like the built-in PreviewMouseWheel
& MouseWheel
events.
Usage
No xmlns
declaration is required to use HorizontalScroll in XAML.
Table of Contents
Behaviors
HorizontalScrollBehavior
can be attached to any ScrollViewer
control to add support for horizontal scrolling by tilting the scroll wheel, or by holding the Shift
key while scrolling up/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
, it's much more maintainable - not to mention faster and easier - to attach it in the code-behind with a style and an EventSetter
instead:
<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
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.