zoukankan      html  css  js  c++  java
  • WPF特效:流光动画效果

    WPF特效——流光动画效果

    一、代码

     <Window.Resources>  
         <!---->
            <Storyboard x:Key="Storyboard1" RepeatBehavior="Forever">
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.StartPoint)" 
                                              Storyboard.TargetName="rectangle">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.855,0.148"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.852,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.148,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.144,0.149"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,0"/>
    
                </PointAnimationUsingKeyFrames>
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.EndPoint)" 
                                              Storyboard.TargetName="rectangle">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.145,0.852"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.148,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.852,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.856,0.851"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,1"/>
    
                </PointAnimationUsingKeyFrames>
            </Storyboard>
         <!---->
            <Storyboard x:Key="Storyboard2" RepeatBehavior="Forever">
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.StartPoint)" 
                                              Storyboard.TargetName="rectangle1">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.855,0.148"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.852,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.148,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.144,0.149"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,0"/>
    
                </PointAnimationUsingKeyFrames>
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.EndPoint)" 
                                              Storyboard.TargetName="rectangle1">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.145,0.852"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.148,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.852,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.856,0.851"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,1"/>
    
                </PointAnimationUsingKeyFrames>
            </Storyboard>
         <!---->
            <Storyboard x:Key="Storyboard3" RepeatBehavior="Forever">
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.StartPoint)" 
                                              Storyboard.TargetName="rectangle2">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.855,0.148"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.852,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.148,0.855"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.144,0.149"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,0"/>
    
                </PointAnimationUsingKeyFrames>
                <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(LinearGradientBrush.EndPoint)" 
                                              Storyboard.TargetName="rectangle2">
                    <EasingPointKeyFrame KeyTime="0:0:0.5" Value="0.145,0.852"/>
                    <EasingPointKeyFrame KeyTime="0:0:1" Value="0.148,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:1.5" Value="0.852,0.145"/>
                    <EasingPointKeyFrame KeyTime="0:0:2" Value="0.856,0.851"/>
                    <EasingPointKeyFrame KeyTime="0:0:2.5" Value="0,1"/>
    
                </PointAnimationUsingKeyFrames>
            </Storyboard>
        </Window.Resources>
        <Window.Triggers>
            <!---->
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
            </EventTrigger>
            <!---->
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard Storyboard="{StaticResource Storyboard2}"/>
            </EventTrigger>
            <!---->
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard Storyboard="{StaticResource Storyboard3}"/>
            </EventTrigger>
        </Window.Triggers>
        <Grid> 
            <!---->
            <Rectangle x:Name="rectangle" Width="300" Height="300" 
                       StrokeThickness="3">
                <Rectangle.Stroke>
                    <LinearGradientBrush  Opacity="0.6">
                        <GradientStop Color="Transparent" Offset="0"/>
                        <GradientStop Color="Violet"  Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Stroke>
    
            </Rectangle>
            <!---->
            <Rectangle x:Name="rectangle1" Width="200" Height="200" 
                       StrokeThickness="3">
                <Rectangle.Stroke>
                    <LinearGradientBrush  Opacity="0.6">
                        <GradientStop Color="Transparent" Offset="0"/>
                        <GradientStop Color="Green"  Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Stroke>
    
            </Rectangle>
            <!---->
            <Rectangle x:Name="rectangle2" Width="100" Height="100" 
                       StrokeThickness="3">
                <Rectangle.Stroke>
                    <LinearGradientBrush  Opacity="0.6">
                        <GradientStop Color="Transparent" Offset="0"/>
                        <GradientStop Color="red"  Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Stroke>
    
            </Rectangle>
    
        </Grid>

    二、特效

    (可惜现在本机没有安装生成Gif图片的软件)


    技术的发展日新月异,随着时间推移,无法保证本博客所有内容的正确性。如有误导,请大家见谅,欢迎评论区指正!
    我创建了一个.NET开发交流群,用于分享学习心得和讨论相关技术难题。欢迎有兴趣的小伙伴扫码入群,相互学习!

  • 相关阅读:
    [编写高质量代码:改善java程序的151个建议]建议72 生成字列表后不要再操作原列表
    [编写高质量代码:改善java程序的151个建议]建议71 推荐使用subList处理局部列表
    [编写高质量代码:改善java程序的151个建议]建议70 子列表只是原列表的一个视图
    程序员的简历到底该怎么写?(转)
    SQL数据库数据优化SQL优化总结( 百万级数据库优化方案)
    sqlserver的四种分页方式
    sql server中截取字符串的常用函数(自己经常到用的时候想不起来所以拿到这里)
    SQL之存储过程详细介绍及语法(篇幅比较长慢慢看)
    超经典SQL练习题,做完这些你的SQL就过关了
    SqlServer 数据库引擎优化顾问优化数据库(消耗内存很大)
  • 原文地址:https://www.cnblogs.com/wml-it/p/14944907.html
Copyright © 2011-2022 走看看