次の方法で共有


所定の位置で要素を回転させる方法

この例では、RotateTransformDoubleAnimationを使用して要素をスピンさせる方法を示します。

次の例では、要素の RenderTransform プロパティに RotateTransform を適用します。 この例では、DoubleAnimation を使用して、RotateTransformAngle をアニメーション化します。 要素を所定の位置にスピンさせるために、要素の 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 Transforms Sample」を参照してください。

関連項目