WPF模糊动画
前台代码
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Microsoft.Samples.Animation.OpacityAnimation.OpacityAnimationExample"
WindowTitle="Opacity Animation Example">
<StackPanel Margin="20,0,0,0" Background="{StaticResource MyGridBrushResource}">
<TextBlock Margin="0,30,0,0" FontWeight="Bold">Animating the Opacity of Elements</TextBlock>
<TextBlock Margin="0,10,0,0">A Button</TextBlock>
<!-- The opacity property of this Button element is animated. -->
<Button Name="opacityAnimatedButton"
HorizontalAlignment="Left" VerticalAlignment="Top">
A Button
</Button>
<TextBlock Margin="0,10,0,0">An Image</TextBlock>
<!-- The opacity property of this Image element is animated. -->
<Image Name="opacityAnimatedImage"
Source="sampleImages\berries.jpg" Stretch="None"
HorizontalAlignment="Left" VerticalAlignment="Top" />
<TextBlock Margin="0,30,0,0" FontWeight="Bold">Animating the Opacity of a Brush</TextBlock>
<!-- The opacity of the brush used to fill this Button element
is animated. -->
<Button Name="opacityAnimatedBrushButton" Background="Orange"
HorizontalAlignment="Left" VerticalAlignment="Top">
A Button
</Button>
<TextBlock Margin="0,30,0,0" FontWeight="Bold"> Animating the Opacity of a Color within a Brush</TextBlock>
<!-- The opacity of one of the colors that comprise the gradient
used to fill this Rectangle element is animated. -->
<Rectangle Name="opacityAnimatedColorRectangle"
Width="120" Height="50" Stroke="Black" StrokeThickness="1"
HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0" Color="MediumBlue" />
<GradientStop Offset="0.75" Color="BlueViolet" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
<Page.Triggers>
<EventTrigger RoutedEvent="Page.Loaded">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard Name="myStoryboard">
<DoubleAnimation Storyboard.TargetName="opacityAnimatedButton"
Storyboard.TargetProperty="(Button.Opacity)" From="1" To="0"
Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetName="opacityAnimatedImage"
Storyboard.TargetProperty="(Image.Opacity)" From="1" To="0"
Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetName="opacityAnimatedBrushButton"
Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Opacity)" From="1" To="0"
Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetName="opacityAnimatedBrushButton"
Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Opacity)" From="1" To="0"
Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
<ColorAnimation Storyboard.TargetName="opacityAnimatedColorRectangle"
Storyboard.TargetProperty="(Rectangle.Fill).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever">
<ColorAnimation.By>
<Color ScA="-1.0" ScR="0.0" ScG="0.0" ScB="0.0" />
</ColorAnimation.By>
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Page.Triggers>
</Page>
后台代码
using System.Windows.Controls;
namespace OpacityAnimation
{
public class OpacityAnimationExample : Page
{
}
}