I have a WPF ListView which currently scrolls everytime I click on an item which is only partially visible. How can I keep the control from scrolling that item into view (instead simply selecting the partially visible one)? This behavior is very annoying when doing a drag from this control.
我有一个WPF ListView,每当我点击一个只能部分可见的项目时,它就会滚动。如何让控件不将该项目滚动到视图中(而只是选择部分可见的项目)?从此控件执行拖动时,此行为非常烦人。
Thanks.
Added: I am looking for a solution to keep the control itself from scrolling when contents are clicked that the control believes are not fully visible. Often this is by a few pixels and the scroll is not necessary.
补充:我正在寻找一种解决方案,以便在单击控件认为不完全可见的内容时保持控件本身不滚动。通常这是几个像素,并且滚动不是必需的。
3 个解决方案
#1
5
The items scroll into view because the default behavior on list item click is to call BringIntoView(). You can add an event handler for the RequestBringIntoView event and catch it before it bubbles up from the ListViewItems to the ScrollViewer. In your handler, check the bounds of the sender against the visible region and if you decide that you don't need to scroll, set the event's Handled flag to true.
这些项目滚动到视图中,因为单击列表项目时的默认行为是调用BringIntoView()。您可以为RequestBringIntoView事件添加事件处理程序,并在它从ListViewItems冒泡到ScrollViewer之前捕获它。在处理程序中,检查发件人对可见区域的界限,如果您决定不需要滚动,请将事件的Handled标志设置为true。
#2
1
Since I'm currently on the road, I cannot try this, but have you tried playing around with CanContentScroll, and/or wrapping the scrollable content into a Panel, as suggested by the ScrollViewer Overview on MSDN?
由于我目前正在旅途中,我无法尝试这一点,但您是否尝试过使用CanContentScroll,和/或将可滚动内容包装到Panel中,如MSDN上的ScrollViewer概述所示?
In the worst case, you might want to replace the ListView
's ItemsPanel
by a hacked ScrollViewer with a "fuzz" factor, e.g. by capturing the RequestBringIntoView
event.
在最坏的情况下,您可能希望使用带有“模糊”因子的被黑客入侵的ScrollViewer替换ListView的ItemsPanel,例如:通过捕获RequestBringIntoView事件。
#3
0
have you tried this approach?
你尝试过这种方法吗?
just as an addon, I don't know how much you know about the subject, but here is a good place to read more about it.
就像一个插件一样,我不知道你对这个主题有多了解,但这里有一个阅读更多关于它的好地方。
added:
I just found that you can prevent the mouse wheel of scrolling as well.
我刚刚发现你也可以防止鼠标滚轮滚动。
#1
5
The items scroll into view because the default behavior on list item click is to call BringIntoView(). You can add an event handler for the RequestBringIntoView event and catch it before it bubbles up from the ListViewItems to the ScrollViewer. In your handler, check the bounds of the sender against the visible region and if you decide that you don't need to scroll, set the event's Handled flag to true.
这些项目滚动到视图中,因为单击列表项目时的默认行为是调用BringIntoView()。您可以为RequestBringIntoView事件添加事件处理程序,并在它从ListViewItems冒泡到ScrollViewer之前捕获它。在处理程序中,检查发件人对可见区域的界限,如果您决定不需要滚动,请将事件的Handled标志设置为true。
#2
1
Since I'm currently on the road, I cannot try this, but have you tried playing around with CanContentScroll, and/or wrapping the scrollable content into a Panel, as suggested by the ScrollViewer Overview on MSDN?
由于我目前正在旅途中,我无法尝试这一点,但您是否尝试过使用CanContentScroll,和/或将可滚动内容包装到Panel中,如MSDN上的ScrollViewer概述所示?
In the worst case, you might want to replace the ListView
's ItemsPanel
by a hacked ScrollViewer with a "fuzz" factor, e.g. by capturing the RequestBringIntoView
event.
在最坏的情况下,您可能希望使用带有“模糊”因子的被黑客入侵的ScrollViewer替换ListView的ItemsPanel,例如:通过捕获RequestBringIntoView事件。
#3
0
have you tried this approach?
你尝试过这种方法吗?
just as an addon, I don't know how much you know about the subject, but here is a good place to read more about it.
就像一个插件一样,我不知道你对这个主题有多了解,但这里有一个阅读更多关于它的好地方。
added:
I just found that you can prevent the mouse wheel of scrolling as well.
我刚刚发现你也可以防止鼠标滚轮滚动。