2012-01-09 9 views
4

私は見つけられないサンプルWPFプログラムを見ました。このサンプルでは、​​ボタンをクリックすると、別のボタンが拡大および縮小を開始します。私がフォームで他のものをやることができる間の平均。これはどうすればいいですか?WPFでコントロールをアニメーション化する方法は?

答えて

9

ボタンをクリックするとボタンの高さが大きくなり、マウスがコントロールから離れると収縮するという非常に簡単な例があります。 WPFのアニメーションは、StoryBoardを使用して行われます。ストーリーボードは通常、EventTriggersにあり、コントロール、ウィンドウ、ページ、またはアプリケーションのリソースに保存できます。以下にいくつかのリソースと一緒にサンプルです:

<Window x:Class="WPFFeatureSample_Application.AnimationWindowSample" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="AnimationWindowSample" Height="300" Width="300"> 
<Grid> 
    <Button Content="Sample" Width="50" Height="50"> 
     <Button.Triggers> 
      <EventTrigger RoutedEvent="Button.Click"> 
       <BeginStoryboard> 
       <Storyboard> 
         <DoubleAnimation To="200" Storyboard.TargetProperty="Width"></DoubleAnimation> 
         <DoubleAnimation To="200" Storyboard.TargetProperty="Height"></DoubleAnimation> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="MouseLeave"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation To="50" Storyboard.TargetProperty="Width"></DoubleAnimation> 
         <DoubleAnimation To="50" Storyboard.TargetProperty="Height"></DoubleAnimation> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Button.Triggers> 
    </Button> 
</Grid> 

参考文献:

http://msdn.microsoft.com/en-us/library/ms742868.aspx

http://windowsclient.net/learn/

1

ストーリーボードを使用してWPFでコントロールをアニメートできます。

MSDNのAnimation Overviewを参照してください。

関連する問題