我的WPF应用程序沿着这些线有动画:如何在动画之间更改TextBlock的Text属性?
a。将TextBlock从000旋转到090.
b。将TextBlock的Text属性更新为新值
c。继续将TextBlock从090旋转到180.
我能够通过向StoryBoard的子项添加两个DoubleAnimations来实现步骤a和c。有没有办法来捕捉第一个动画的结尾做一些工作?
谢谢。
我的WPF应用程序沿着这些线有动画:如何在动画之间更改TextBlock的Text属性?
a。将TextBlock从000旋转到090.
b。将TextBlock的Text属性更新为新值
c。继续将TextBlock从090旋转到180.
我能够通过向StoryBoard的子项添加两个DoubleAnimations来实现步骤a和c。有没有办法来捕捉第一个动画的结尾做一些工作?
谢谢。
您可以创建两个故事板,一个用于旋转90和另180当第一个故事板完成,更新文本,然后开始下一个故事板。
Storyboard rotateTo90 = new Storyboard();
// Add rotate animation
rotateTo90.Completed += (s,e) =>
{
TextBlock1.Text = "Updated";
Storyboard rotateTo180 = new Storyboard();
// Add rotate animation
rotateTo180.Begin();
};
rotateTo90.Begin();
您可以添加一个BooleanAnimationUsingKeyFrames并使用它来设置值。
[对于.NET框架4.5及更高版本]
您可以使用StringAnimationUsingKeyFrames类来修改使用DiscreteStringKeyFrame文本。以下是example。
<Button Name="myAnimatedButton" Margin="200"
FontSize="16pt" FontFamily="Verdana">Some Text
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<StringAnimationUsingKeyFrames
Storyboard.TargetName="myAnimatedButton" Storyboard.TargetProperty="(Button.Content)"
Duration="0:0:8" FillBehavior="HoldEnd">
<!-- All the key frames below are DiscreteStringKeyFrames. Discrete key frames create
sudden "jumps" between values (no interpolation). Only discrete key frames can be used
for String key frame animations. -->
<DiscreteStringKeyFrame Value="" KeyTime="0:0:0" />
<DiscreteStringKeyFrame Value="A" KeyTime="0:0:1" />
<DiscreteStringKeyFrame Value="An" KeyTime="0:0:1.5" />
<DiscreteStringKeyFrame Value="Ani" KeyTime="0:0:2" />
<DiscreteStringKeyFrame Value="Anim" KeyTime="0:0:2.5" />
<DiscreteStringKeyFrame Value="Anima" KeyTime="0:0:3" />
<DiscreteStringKeyFrame Value="Animat" KeyTime="0:0:3.5" />
<DiscreteStringKeyFrame Value="Animate" KeyTime="0:0:4" />
<DiscreteStringKeyFrame Value="Animated" KeyTime="0:0:4.5" />
<DiscreteStringKeyFrame Value="Animated " KeyTime="0:0:5" />
<DiscreteStringKeyFrame Value="Animated T" KeyTime="0:0:5.5" />
<DiscreteStringKeyFrame Value="Animated Te" KeyTime="0:0:6" />
<DiscreteStringKeyFrame Value="Animated Tex" KeyTime="0:0:6.5" />
<DiscreteStringKeyFrame Value="Animated Text" KeyTime="0:0:7" />
</StringAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
感谢.NET框架中动画集合的最新增加。
谢谢。正是我在找什么! –