Animated WPF animations are controlled by AnimationClock (sort of like a fancy timer). AnimationClock has a CurrentProgress property, which ranges from 0 to 1; where 0 is the starting point and 1 is the ending point. A repeating storyboard gradually changes CurrentProgress from 0 to 1 to 0 ... 1 /
AnimationClock , CurrentTimeInvalidated. AnimationClock. CurrentProgress. , , CurrentProgress, , 0 1. . , , .
xaml:
<Grid x:Name="uxGrid" Background="White">
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="uxGrid" Changed="ColorAnimation_Changed" CurrentTimeInvalidated="ColorAnimation_CurrentTimeInvalidated" Storyboard.TargetProperty="Background.Color" From="Blue" To="Green" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
</Grid>
:
private double? _clockLastProgress;
private bool _clockLastDecreased;
private void ColorAnimation_CurrentTimeInvalidated(object sender, EventArgs e)
{
AnimationClock clock = sender as AnimationClock;
if (clock != null && clock.CurrentProgress.HasValue)
{
if (!_clockLastProgress.HasValue)
{
}
else
{
if (_clockLastDecreased)
{
if (clock.CurrentProgress > _clockLastProgress)
{
_clockLastDecreased = false;
}
}
else
{
if (clock.CurrentProgress < _clockLastProgress)
{
_clockLastDecreased = true;
}
}
}
_clockLastProgress = clock.CurrentProgress.Value;
}
}