【问题标题】:WPF XAML Animation (Newbie)WPF XAML 动画(新手)
【发布时间】:2012-11-01 06:40:19
【问题描述】:

我正在尝试在 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>

【问题讨论】:

    标签: wpf xaml animation


    【解决方案1】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-19
        • 2021-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-02
        • 2016-03-06
        • 2013-01-23
        相关资源
        最近更新 更多