平滑旋转 Viewbox 内容
我希望自学更好的方法来在 WPF 中执行通常手动执行的操作。
在本例中,我有一个包含图像的 ViewBox。我还有一个使用 DoubleAnimation 将图像向右旋转 90 度的按钮。
这个动画效果很好,但显然因为它在旋转时是方形的,所以图像对 ViewBox 进行了“最佳拟合”,这使得旋转看起来很糟糕,因为随着它的最长边缘收缩或增长以适应它,它会变得越来越大和越来越小特定的旋转角度。
我正在寻找有关使用适当的 WPF 方法处理此问题的最佳方法的任何建议。显然,我可以手动完成所有计算,但我更感兴趣的是找到一种使用 .NET 架构中内置的控件和方法的方法。
感谢您的帮助。
I'm looking to teach myself better methods of doing things in WPF that I would normally do manually.
In this case, I have a ViewBox with an image in it. I also have a button that uses a DoubleAnimation to rotate the image 90 to the right.
This animation works fine, but obviously because it's square as it turns, the image does a "best fit" to the ViewBox which makes the rotation look quite bad, as it gets larger and smaller as its longest edge shrinks or grows to fit to that particular rotation angle.
I am looking for any advice on the best way to handle this using appropriate WPF methods. Obviously I could do all the calculations manually, but I would be more interested in finding a way to use the controls and methods built into the .NET architecture.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
ViewBox
中只有一个Image
,请放下视图框。将Stretch
属性设置为Uniform
后,图像就已经能够正确拉伸。无论如何,请使用
RenderTransform
而不是LayoutTransform
,以避免在图像旋转时重新计算控件的位置。在完成所有位置计算后,RenderTransform
将旋转对象,这样就可以了。如果您发现图像在旋转时超出了某些控制,只需在图像周围添加边距即可。If you only have an
Image
in yourViewBox
, drop the view box. An image is already capable of stretching correctly with theStretch
attribute set toUniform
.In any case, use a
RenderTransform
instead of aLayoutTransform
, to avoid recalculating the position of the controls when the images rotates.RenderTransform
will rotate the object after all position calculations are done so you'll be fine. Just add a margin around the image if you find that it pass over some control while rotating.