我有一个专为触摸显示器设计的全屏WPF应用程序,我在主屏幕上有一些Listbox
。
当我点击“列表框”时,它滚动得很好,但是当它到达列表的末尾时,整个应用程序从屏幕顶部被拉下来,我可以停止这种行为不知何故?
有没有人见过这个?
答案 0 :(得分:33)
是的,ListBox的默认行为(或者更确切地说,默认ListBox模板中的ScrollViewer)是很奇怪 - 当我第一次遇到它时,我认为它一定是个恶作剧。事实上,很难找到任何关于它的文档 - 但简要提到here:
ManipulationBoundaryFeedback事件使应用程序或组件在对象到达边界时提供视觉反馈。例如,Window类处理ManipulationBoundaryFeedback事件,导致窗口在遇到边缘时略微移动。
所以,解决它的方法是在ListBox上处理ManipulationBoundaryFeedback,并将Handled设置为true:
<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback">
// ...
</ListBox>
代码隐藏:
private void OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}