WPF模糊动画

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
    {
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值