在ListView上用鼠标激活水平滚动 [英] Activate horizontal scrolling with mouse on ListView
本文介绍了在ListView上用鼠标激活水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义的水平ListView,在它的模板(使用Blend创建)中带有自定义的ScrollViewer.当使用鼠标滚轮时,我希望它水平滚动. 我该怎么办?
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\right 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();
}
}
}
xaml:
<ScrollViewer x:Name="myScrollViewer" HorizontalScrollBarVisibility="Visible" Mouse.PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
这篇关于在ListView上用鼠标激活水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文