Im trying to rotate a <Image>
of an arrow (placed in the middle of a 40x40 image). By what I remember from graphics class i need to first translate the image back to its center, rotate and then translate back:
TranslateTransform tTrans = new TranslateTransform();
tTrans.X -= 20;
tTrans.X -= 20;
RotateTransform rTrans = new RotateTransform();
rTrans.Angle = 60;
TranslateTransform t2Trans = new TranslateTransform();
tTrans.X += 20;
tTrans.X += 20;
imgWind.RenderTransform = ?;
Anyone got a good idea on how i can apply the transformations?
You can simply use
imgWind.RenderTransform = new RotateTransform(){ CenterX = 0.5, CenterY = 0.5, Angle = 45 };
Or in XAML:
<UIElement RenderTransformOrigin="0.5,0.5">
<UIElement.RenderTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="45" />
</UIElement.RenderTransform>
</UIElement>
By setting the CenterX and CenterY you don't have to translate before and after. In WPF (or silverlight for that matter) the transforms will take care of that themselfs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With