如何将速度和/或加速度合并到 (WPF) 滚动查看器中?
我有一个用于平移的 WPF 滚动查看器(MouseDown、MouseMove、MouseUp),并且我希望包含一个结合惯性的加速效果。因此,如果鼠标移动超过阈值速度并且我释放鼠标,它会继续平移,但会根据初始速度减慢。有什么想法、想法或例子吗?
I have a WPF scrollViewer that I use for panning (MouseDown, MouseMove, MouseUp) and I would like to include an acceleration effect that incorporates inertia. So, if the mouse moves beyond a threshold speed and I release the mouse, it continues to pan but slows down as a function of the initial speed. Any ideas, thoughts or examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前基本上已经完成了这一点,并从查看 ScrollViewer 开始,但最终将其丢弃并使用带有 Canvas 的 Viewbox 作为内容的绝对定位子项(我支持缩放以及滚动,它基本上是 DeepZoom 没有用于缩放的缩放图像,因此存在像素化当放大时)。我编写了用于根据鼠标事件确定手势方向和手势速度的代码,并将其转换为滚动方向和速度,然后对可滚动内容的 Canvas.Left 和 Canvas.Top 属性(位于 Children 集合中)进行动画处理Viewbox 的子 Canvas)和 DoubleAnimation。它运作良好,但是可能有更好的方法...这里 一个建议通过 Frame 控件在 WPF 中托管 DeepZoom 的线程(尽管我不会那样做)。
编辑:基本上 ScrollViewer 的限制太多了。即使您进入 ControlTemplate 并直接获取对 ScrollBars 的引用,您也需要为这些滚动条的 Thumb 位置设置动画,我很确定这是我发现我无法做到的(它是大约 3 年前:)
I've done basically this before and started by looking at ScrollViewer but in the end threw it away and used a Viewbox with a Canvas as the child for absolute positioning of content (I was supporting zoom aswel as scroll, it was basically DeepZoom without the scaled images for zooming so there was pixelation when zoomed right in). I wrote code for determining the gesture direction and the speed of the gesture from the mouse events and converted this to a scroll direction and speed and then animated the Canvas.Left and Canvas.Top properties of the scrollable content (which was in the Children collection of the Viewbox's child Canvas) with DoubleAnimation. It worked well, however there may be a better way...heres a thread suggesting hosting DeepZoom in WPF via a Frame control (although I wouldn't do it that way).
EDIT: Basically the ScrollViewer was just too restricting. Even if you get into the ControlTemplate and get references to the ScrollBars directly, it is the position of the Thumb of these scrollbars that you would need to animate and I'm pretty sure this is what I found I couldn't do (it was almost 3 years ago :)