在 ListView 上用鼠标激活水平滚动 [英] Activate horizontal scrolling with mouse on ListView
本文介绍了在 ListView 上用鼠标激活水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义的水平 ListView,它的模板中带有自定义的 ScrollViewer(使用 Blend 创建).我希望它在使用鼠标滚轮时水平滚动.我该怎么做?
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?
推荐答案
如果你实现了 IScrollInfo
你可以覆盖 MouseWheelUp
来做 MouseWheelLeft
并以相同的方式向下向右
if you implement IScrollInfo
you can override the MouseWheelUp
to do MouseWheelLeft
and down
ight the in same way
编辑(更简单):
添加到您的 ScrollViewer PreviewMouseWheel
add to your ScrollViewer PreviewMouseWheel
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta < 0) // wheel down
{
if (myScrollViewer.HorizontalOffset + e.Delta > 0)
{
myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + e.Delta);
}
else
{
myScrollViewer.ScrollToLeftEnd();
}
}
else //wheel up
{
if (myScrollViewer.ExtentWidth > myScrollViewer.HorizontalOffset + e.Delta)
{
myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + e.Delta);
}
else
{
myScrollViewer.ScrollToRightEnd();
}
}
}
xml:
<ScrollViewer x:Name="myScrollViewer" HorizontalScrollBarVisibility="Visible" Mouse.PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
这篇关于在 ListView 上用鼠标激活水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文