<Window x:Class="WPFAnimation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ellipse Height="50" Width="100">
<Ellipse.Fill>
<SolidColorBrush x:Name="ellipseBrush" Color="Yellow"/>
</Ellipse.Fill>
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Duration="00:00:06" RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetProperty="(Ellipse.Width)" Duration="0:0:3" AutoReverse="True"
FillBehavior="Stop" RepeatBehavior="Forever" AccelerationRatio="0.9" DecelerationRatio="0.1"
From="100" To="300"/>
<ColorAnimation Storyboard.TargetName="ellipseBrush" Storyboard.TargetProperty="(SolidColorBrush.Color)"
Duration="0:0:3" AutoReverse="True" FillBehavior="Stop" RepeatBehavior="Forever"
From="Yellow" To="Red"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ellipse Height="50" Width="100">
<Ellipse.Fill>
<SolidColorBrush x:Name="ellipseBrush" Color="Yellow"/>
</Ellipse.Fill>
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Duration="00:00:06" RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetProperty="(Ellipse.Width)" Duration="0:0:3" AutoReverse="True"
FillBehavior="Stop" RepeatBehavior="Forever" AccelerationRatio="0.9" DecelerationRatio="0.1"
From="100" To="300"/>
<ColorAnimation Storyboard.TargetName="ellipseBrush" Storyboard.TargetProperty="(SolidColorBrush.Color)"
Duration="0:0:3" AutoReverse="True" FillBehavior="Stop" RepeatBehavior="Forever"
From="Yellow" To="Red"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
</Grid>
</Window>
本文展示了一个使用WPF框架创建的动态效果示例。该示例通过Ellipse元素实现了一个圆形对象,在加载时触发动画,使其宽度在100到300之间变化,并同时改变填充颜色从黄色变为红色,动画时长为6秒并无限循环播放。
5073

被折叠的 条评论
为什么被折叠?



