Rotating Viewbox contents smoothly
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.
精彩评论