此示例演示如何使用RotateTransform和DoubleAnimation使元素旋转。
以下示例将 RotateTransform 应用于 RenderTransform 元素的属性。 该示例使用DoubleAnimation为RotateTransform的Angle添加动画效果。 为了使元素旋转到位,该示例将元素的属性设置为 RenderTransformOrigin 点(0.5,0.5)。
示例:
<!-- RotateAboutCenterExample.xaml
This example shows how to make an element spin
about its center. -->
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Microsoft.Samples.Animation.RotateAboutCenterExample"
WindowTitle="Rotate About Center Example">
<StackPanel Margin="50">
<Button
RenderTransformOrigin="0.5,0.5"
HorizontalAlignment="Left">
Hello,World
<Button.RenderTransform>
<RotateTransform x:Name="MyAnimatedTransform" Angle="0" />
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyAnimatedTransform"
Storyboard.TargetProperty="(RotateTransform.Angle)"
From="0.0" To="360" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
</Page>
有关包含更多转换示例的完整示例,请参阅 2D 转换示例。