WPF Rotate rectangle animation in XAML

自古美人都是妖i 提交于 2019-12-03 01:19:01

Something like this

<Rectangle x:Name="rect1" RenderTransformOrigin="0.5, 0.5">
  <Rectangle.RenderTransform>
    <!-- giving the transform a name tells the framework not to freeze it -->
    <RotateTransform x:Name="noFreeze" />
  </Rectangle.RenderTransform>
  <Rectangle.Triggers>
    <EventTrigger RoutedEvent="Loaded">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation
            Storyboard.TargetProperty="(Rectangle.RenderTransform).(RotateTransform.Angle)"
            To="-360" Duration="0:0:1" RepeatBehavior="Forever" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers>
</Rectangle>

Of course you can remove Loaded trigger and run this storyboard whenever you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!