WPF XAML 动画(新手)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13350512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF XAML Animation (Newbie)
提问by ragnarius
I am trying to test animation in XAML. My intension was to make a font-size pulse (increase and decrease forever). But when I type in the code below, Visual studio does not recognize the class DoubleAnimation. What am I doing wrong?
我正在尝试在 XAML 中测试动画。我的意图是制造一个字体大小的脉冲(永远增加和减少)。但是当我输入下面的代码时,Visual Studio 无法识别 class 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>
回答by Federico Berasategui
You need to declare a Storyboardand start it upon load:
您需要声明 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>
回答by Rohit Vats
You need to use Storyboardfor running animation -
您需要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>
To learn more about animations follow this link here.
要了解有关动画的更多信息,请点击此处的链接。

