WPF XAML 动画(新手)

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>
2个回答

6
您需要声明一个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>

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>

想要了解关于动画的更多信息,请点击这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接