Several ways to do this.
with keyframes:
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Background.Color">
<DiscreteColorKeyFrame Value="Red" KeyTime="0:0:0" />
<DiscreteColorKeyFrame Value="Red" KeyTime="0:0:1" />
<LinearColorKeyFrame Value="White" KeyTime="0:0:2" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
with two animations in sequence:
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
From="Red" To="Red" Duration="0:0:1" />
<ColorAnimation Storyboard.TargetProperty="Background.Color"
To="White" BeginTime="0:0:1" Duration="0:0:1" />
</Storyboard>
with custom attenuation function:
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
From="Red" To="White" Duration="0:0:2">
<ColorAnimation.EasingFunction>
<local:CustomEasingFunction />
</ColorAnimation.EasingFunction>
</ColorAnimation>
</Storyboard>
In this case, a function that shows the transition in the first half of the duration and holds the value in the second half. Since EasingMode is EaseOut by default, this function will βplayβ backward.
public class CustomEasingFunction : EasingFunctionBase
{
public CustomEasingFunction() : base()
{ }
protected override double EaseInCore(double normalizedTime)
{
return (normalizedTime < 0.5)
? normalizedTime * 2
: 1;
}
protected override Freezable CreateInstanceCore()
{
return new CustomEasingFunction();
}
}
Lpl source
share