wpf 围绕中心旋转图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13034201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wpf rotate image around center
提问by 7heViking
I have an image on a button which I would like to rotate when the user clicks it. I allmost have it to work. The image rotates fine on click, but it doesn't rotate round its center.
我在按钮上有一个图像,当用户单击它时我想旋转它。我几乎有它的工作。单击时图像可以很好地旋转,但不会围绕其中心旋转。
How can I make the image rotate around its center and not the top left corner?
如何使图像围绕其中心而不是左上角旋转?
Here is my code:
这是我的代码:
<Button Name="btnRefreshPortList"
Grid.Column="1"
Margin="10 0 0 0"
Command="{Binding RefreshPortList}">
<Image Source="Images/refresh.jpg"
Height="15">
<Image.RenderTransform>
<RotateTransform x:Name="AnimatedRotateTransform" Angle="0" />
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="MouseDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="AnimatedRotateTransform"
Storyboard.TargetProperty="Angle"
By="10"
To="360"
Duration="0:0:0.5"
FillBehavior="Stop" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</Button>
BR FireFly3000
BR萤火虫3000
回答by Thomas Levesque
Just set RenderTransformOrigin
to (0.5, 0.5) on the image
只需RenderTransformOrigin
在图像上设置为 (0.5, 0.5)
<Image Source="Images/refresh.jpg"
RenderTransformOrigin=".5,.5"
Height="15">
...