4

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

<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>
4

2 回答 2

6

您需要声明 aStoryboard并在加载时启动它:

 <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>
于 2012-11-12T19:59:59.177 回答
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>

要了解有关动画的更多信息,请点击此处的链接。

于 2012-11-12T20:02:12.960 回答