2012-11-12 50 views
2

我想在XAML中测试动画。我的意图是制作一个字体大小的脉冲(永远增加和减少)。但是,当我输入下面的代码时,Visual Studio无法识别类DoubleAnimation。我究竟做错了什么?WPF XAML动画(新手)

<Window x:Class="testingAnimation.MainWindow" 
     xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
     Title="MainWindow" Height="350" Width="525"> 
<StackPanel> 
    <TextBlock Text="HELLO"> 
     <TextBlock.FontSize> 
      <DoubleAnimation /> 
     </TextBlock.FontSize> 
    </TextBlock> 
</StackPanel> 
</Window> 

回答

5

你需要声明一个Storyboard并启动它后负荷:

<TextBlock x:Name="Text" Text="Hello!!"> 
      <TextBlock.Triggers> 
       <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
        <EventTrigger.Actions> 
         <BeginStoryboard> 
          <Storyboard Duration="00:00:01" RepeatBehavior="Forever" AutoReverse="True"> 
           <DoubleAnimation From="10" To="20" Storyboard.TargetName="Text" Storyboard.TargetProperty="FontSize"/> 
          </Storyboard>        
         </BeginStoryboard> 
        </EventTrigger.Actions> 
       </EventTrigger> 
      </TextBlock.Triggers> 
    </TextBlock> 
+0

谢谢,我想我必须阅读更多故事板.. – ragnarius

2

您需要使用Storyboard运行动画 -

<TextBlock x:Name="textBlock" Text="HELLO"> 
    <TextBlock.Triggers> 
     <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
      <BeginStoryboard> 
       <Storyboard RepeatBehavior="Forever" AutoReverse="True"> 
        <DoubleAnimation Storyboard.TargetName="textBlock" 
           Storyboard.TargetProperty="FontSize" 
           From="10" To="30" 
           Duration="0:0:1"/> 
        </Storyboard> 
      </BeginStoryboard> 
      </EventTrigger> 
     </TextBlock.Triggers> 
</TextBlock> 

要了解更多关于动画请点击此链接here

+0

谢谢,我想我必须阅读更多故事板.. – ragnarius