具有触摸惯性的WPF列表框拉下整个窗口 [英] WPF Listbox with touch inertia pulls down entire window

查看:13
本文介绍了具有触摸惯性的WPF列表框拉下整个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为触摸显示器构建的全屏 WPF 应用程序,并且我在主屏幕上有一些 Listbox.

I have a full screen WPF application built for a touch monitor, and I have some Listboxs on the main screen.

当我轻弹列表框"时,它滚动正常,但是当它到达列表末尾时,整个应用程序从屏幕顶部拉下,我可以停止这种行为吗不知何故?

When I flick the 'Listbox' it scrolls fine, but when it gets to the end of the list, the entire application gets pulled down from the top of the screen, can I stop this behavior somehow?

还有其他人看过吗?

推荐答案

是的,ListBox 的默认行为(或者更确切地说,默认 ListBox 模板中的 ScrollViewer)奇怪 - 当我第一次看到它,我想这一定是一个恶作剧.事实上,很难找到任何关于它的文档 - 但它被简要提及 这里:

Yes, that default behaviour of the ListBox (or rather, the ScrollViewer inside the default ListBox template) is weird - when I first came across it, I thought it must be a practical joke. In fact, it's really hard to find any documentation about it - but it is briefly mentioned here:

ManipulationBoundaryFeedback 事件使应用程序或组件能够在对象碰到边界时提供视觉反馈.例如,Window 类处理 ManipulationBoundaryFeedback 事件以使窗口在遇到其边缘时略微移动.

The ManipulationBoundaryFeedback event enables applications or components to provide visual feedback when an object hits a boundary. For example, the Window class handles the ManipulationBoundaryFeedback event to cause the window to slightly move when its edge is encountered.

因此,一种解决方法是处理 ListBox 上的 ManipulationBoundaryFeedback,并将 Handled 设置为 true:

So, a way around it is to handle ManipulationBoundaryFeedback on the ListBox, and set Handled to true:

<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback">            
  // ...
</ListBox>

代码隐藏:

private void OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
    e.Handled  = true;
}

这篇关于具有触摸惯性的WPF列表框拉下整个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆