开发者

Rotating Viewbox contents smoothly

开发者 https://www.devze.com 2023-01-03 19:59 出处:网络
I\'m looking to teach myself better methods of doing things in WPF that I would normally do manually.

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.开发者_如何学JAVA

Thanks for your help.


If you only have an Image in your ViewBox, drop the view box. An image is already capable of stretching correctly with the Stretch attribute set to Uniform.

In any case, use a RenderTransform instead of a LayoutTransform, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消