wpf 围绕中心旋转图像 [英] wpf rotate image around center

查看:50
本文介绍了wpf 围绕中心旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个按钮上有一个图像,当用户点击它时我想旋转它.我几乎有它的工作.单击时图像可以很好地旋转,但不会围绕其中心旋转.

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?

这是我的代码:

<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萤火虫3000

推荐答案

只需将图像上的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆