次の方法で共有


方法: ポップアップをアニメーション化する

この例では、Popup コントロールをアニメーション化する 2 つの方法を示します。

次の例では、PopupAnimation プロパティが値 Slide に設定されています。それにより、Popup は表示時、"スライドイン" します。

Popup を回転させるため、この例では、Popup の子要素である CanvasRenderTransform プロパティに RotateTransform が割り当てられています。

変換を正しく機能させるため、この例では、AllowsTransparency プロパティを true に設定する必要があります。 また、Popup が回転するために十分な空間を CanvasMargin で指定する必要があります。

<Popup IsOpen="{Binding ElementName=myCheckBox,Path=IsChecked}" 
       PlacementTarget="{Binding ElementName=myCheckBox}"            
       AllowsTransparency="True"
       PopupAnimation="Slide"
       HorizontalOffset="50"
       VerticalOffset="50"
       >
  <!--The Margin set on the Canvas provides the additional 
      area around the Popup so that the Popup is visible when 
      it rotates.-->
  <Canvas Width="100" Height="100" Background="DarkBlue"
          Margin="150">
    <Canvas.RenderTransform>
      <RotateTransform x:Name="theTransform" />
    </Canvas.RenderTransform>
    <TextBlock TextWrapping="Wrap" Foreground="White">
      Rotating Popup
    </TextBlock>
  </Canvas>
</Popup>

次の例では、Button のクリック時に発生する Click イベントによって、アニメーションを開始する Storyboard がトリガーされるしくみを示します。

<Button HorizontalAlignment="Left" Width="200" Margin="20,10,0,0">
  <Button.Triggers>
    <EventTrigger RoutedEvent="Button.Click">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation 
            Storyboard.TargetName="theTransform"
            Storyboard.TargetProperty="(RotateTransform.Angle)" 
            From="0" To="360" Duration="0:0:5" AutoReverse="True"/>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Button.Triggers>
  Click to see the Popup animate
</Button>

関連項目