WPF 使用Scrollviewer滑动时窗口抖动的问题

今天在运行桌面程序时,使用WPF的Scrollviewer控件,在使用手指滑动时,出现了窗体的抖动效果,感觉很奇怪;

查询资料,可以通过拦截处理ManipulationBoundaryFeedback事件解决,详细如下。

1. 在xaml页面对ScrollViewer页面添加ManipulationBoundaryFeedback事件,添加完毕后会有提示,直接生成cs的事件处理方法;

<ScrollViewer VerticalScrollBarVisibility = "Hidden" PanningMode="verticalOnly" ManipulationBoundaryFeedback="ScrollViewer_ManipulationBoundaryFeedback">
    <!-- your content is here... -->
</ScrollViewer>

2. 在后台代码页面,需要对生成的事件进行处理,将Handld设置为true即可,代码如下

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

3. 至此,窗体抖动问题即可解决,另外,下面两个属性分别是设置竖向滑动条是否可见,和设置只支持竖向滑动。

VerticalScrollBarVisibility = "Hidden" PanningMode="verticalOnly"
posted @ 2022-03-16 10:14  Logan1418  阅读(352)  评论(0)    收藏  举报