我正在寻找一种在纯Property
动画后设置xaml
的方法。
Msdn has an example of how to do that in xaml
+ codebehind
:
XAML:
<Button
Content="Animate and Then Set Example 1">
<Button.Background>
<SolidColorBrush x:Name="Button1BackgroundBrush"
Color="Red" />
</Button.Background>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="Button1BackgroundBrush"
Storyboard.TargetProperty="Color"
From="Red" To="Yellow" Duration="0:0:5"
FillBehavior="HoldEnd"
Completed="setButton1BackgroundBrushColor" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
C#:
private void setButton1BackgroundBrushColor(object sender, EventArgs e)
{
Button1BackgroundBrush.Color = Colors.Blue;
}
答案 0 :(得分:0)
在这种特殊情况下,您可以添加另一个ColorAnimation
,并通过其BeginTime
属性对其进行适当延迟,如下所示:
<Storyboard>
<ColorAnimation
Storyboard.TargetName="Button1BackgroundBrush"
Storyboard.TargetProperty="Color"
From="Red" To="Yellow" Duration="0:0:5" />
<ColorAnimation
Storyboard.TargetName="Button1BackgroundBrush"
Storyboard.TargetProperty="Color"
To="Blue" Duration="0"
BeginTime="0:0:5" />
</Storyboard>
在更一般的情况下,根据属性类型,您可以以类似的方式使用适当的动画(如果存在)。