<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="simple_animation">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
<EasingColorKeyFrame KeyTime="0" Value="#FF21AB49"/>
<EasingColorKeyFrame KeyTime="0:0:0.3" Value="#FFAB4721"/>
<EasingColorKeyFrame KeyTime="0:0:0.7" Value="#FF21AB49"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource simple_animation}"/>
</EventTrigger>
</Window.Triggers>
<Grid Margin="0,12,0,0">
<Rectangle x:Name="rectangle" Fill="#FF21AB49" Margin="136,93,92,157" Stroke="Black"/>
</Grid>
上面的简单动画代码。首先,您必须创建 Storyboard 来制作动画,然后只有您可以制作想要制作动画的动画。请尝试上面的代码,它将对您有所帮助。