WPF绕中心形象 [英] wpf rotate image around center
本文介绍了WPF绕中心形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想,当用户点击它旋转按钮的图像。我的allmost有它的工作。图像旋转上点击很好,但它不旋转轮的中心。
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?
下面是我的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 FireFly3000
推荐答案
只要设置 RenderTransformOrigin
来(0.5,0.5),在图像上
Just set RenderTransformOrigin
to (0.5, 0.5) on the image
<Image Source="Images/refresh.jpg"
RenderTransformOrigin=".5,.5"
Height="15">
...
这篇关于WPF绕中心形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文