I've got a custom horizontal ListView with custom ScrollViewer inside it's template (created with Blend). I want it to scroll horizontally when using mouse scrolling wheel. How can I do that?
相关问题
- VNC control for WPF application
- How to create Circular view on android wear?
- Use JS/jQuery to scroll a div's content that h
- WPF Binding from System.Windows.SystemParameters.P
- JSON Exception - No value for wanted parameter
if you implement
IScrollInfo
you can override theMouseWheelUp
to doMouseWheelLeft
and down\right the in same wayedit (much more simple):
add to your ScrollViewer PreviewMouseWheel
xaml:
I was kinda looking for the most simple way to make any
ScrollViewer
scroll left-right instead of up-down. So here is the simplest combination of the other answers.and:
Xaml Code:
C# Code
This should be done with a
Behavior
for greater reusability. Also, the logic from ZSH is redundant and could be simplified. Here's my code:You'll need to add the following references:
System.Windows
,System.Windows.Controls
,System.Windows.Input
, and you may need to get the Blend SDK NuGet package, and find and reference theSystem.Windows.Interactivity
DLL in the Assemblies Extensions section.Use this for
VisualTreeHelpers
:Reference: https://codereview.stackexchange.com/questions/44760/is-there-a-better-way-to-get-a-child
Note that it is NOT the same as
VisualTreeHelper
inWindows.System.Media
.Here's how to use it in XAML:
Where the
i
namespace is declared asxmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
andbehaviors
is declared asxmlns:behaviors="clr-namespace:MyNamespace"
where
MyNamespace
is the namespace that contains theHorizontalScrollBehavior
class.