问题描述
在我的WPF应用程序我有一个的ListView
的 ScrollViewer.VerticalScrollBarVisibility
设置为残疾人
。它包含一个的ScrollViewer
之内。当我尝试通过的ListView
来使用鼠标滚轮,外的ScrollViewer
不滚动,因为的ListView
正在捕获滚动事件。
In my WPF application I have a ListView
whose ScrollViewer.VerticalScrollBarVisibility
is set to Disabled
. It is contained within a ScrollViewer
. When I attempt to use the mouse wheel over the ListView
, the outer ScrollViewer
does not scroll because the ListView
is capturing the scroll events.
我怎么能强迫的ListView
,允许滚动事件冒泡到的ScrollViewer
?
How can I force the ListView
to allow the scroll events to bubble up to the ScrollViewer
?
推荐答案
您需要捕获preVIEW鼠标滚轮事件在内部列表视图
You need to capture the preview mouse wheel event in the inner listview
ctl.PreviewMouseWheel += PreviewMouseWheel;
然后从滚动列表视图停止活动,提高在父列表视图的事件。
then stop the event from scrolling the listview and raise the event in the parent listview.
private static void PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if (!e.Handled)
{
e.Handled = true;
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
eventArg.RoutedEvent = UIElement.MouseWheelEvent;
eventArg.Source = sender;
var parent = ((Control)sender).Parent as UIElement;
parent.RaiseEvent(eventArg);
}
}
Creds去@罗伯特 - 瓦格纳谁在几个月前解决了这个给我。
Creds go to @robert-wagner who solved this for me a few months ago.
这篇关于从一个ListView其父冒泡滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!