问题描述
我正在尝试使用XAML ScrollViewer便宜地"将捏缩放添加到图像.但是,问题在于,在图像周围平移时,图像始终保持最靠左.如果我向右滑动它,看起来不错,但是第二次释放图像时,它会向左对齐.
I am trying to use a XAML ScrollViewer to 'cheaply' add pinch-zooming to an image. The issue however is that when panning around the image, it keeps snapping to the very left. If I slide it right, it looks fine, but the second I release the image, it snaps back to the left.
此问题仅在水平方向上仍然存在-对于垂直平移,它可以正常工作.
This problem only persists horizontally - for vertical panning, it works fine.
我将其抽象为最简单的测试用例,并且一直存在.我的XAML代码如下:
I abstracted this to the most simple test case, and it persists. My XAML code is as follows:
<ScrollViewer>
<Image Source="http://i.imgur.com/1WlGT.jpg" />
</ScrollViewer>
感谢您的帮助.
推荐答案
我已经解决了这个问题.
I've resolved this.
问题是您必须明确将HorizontalScrollBarVisibility设置为true.
The issue is you have to explicityl set HorizontalScrollBarVisibility to true.
<ScrollViewer x:Name="scrollViewer"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
ZoomMode="Enabled">
<Image Source="http://i.imgur.com/1WlGT.jpg" />
</ScrollViewer>
这篇关于使用ScrollViewer进行图像缩放时,可以保持向左平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!