基于vs和C#的WPF应用之动画3

注:1、在内部和外部使用缓动函数

cs 复制代码
<Grid.Resources>
<PowerEase x:Key="powerease" Power="3" EasingMode="EaseInOut"/>
</Grid.Resources>
<DoubleAnimation EasingFunction="{StaticResource powerease}"/>


 <DoubleAnimation.EasingFunction>
 <PowerEase EasingMode="EaseInOut" Power="3"/>
 </DoubleAnimation.EasingFunction>

一、画布

cs 复制代码
<Canvas x:Name="canvas3" Width="200" Height="200" Grid.Row="0" Grid.Column="1">
            <Canvas.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard Storyboard="{StaticResource third_sb}"/>
                </EventTrigger>
            </Canvas.Triggers>

            <!--背景-->
            <Ellipse Width="100" Height="100" Fill="#f2f4f6" Margin="50"/>
            <Label Content="Loading"
               FontSize="16"
               Margin="50"
               FontFamily="Times New Roman"
               Foreground="#6b48ff"
               FontWeight="Bold"
               Width="100" 
               Height="100"
               VerticalContentAlignment="Center" 
               HorizontalContentAlignment="Center"/>

            <Ellipse Name="third_e1" Style="{StaticResource thirdStyle_Ellipse}" >
                <Ellipse.RenderTransform>
                    <RotateTransform Angle="0"/>
                </Ellipse.RenderTransform>
            </Ellipse>
            <Ellipse Name="third_e2" Style="{StaticResource thirdStyle_Ellipse}">
                <Ellipse.RenderTransform>
                    <RotateTransform Angle="0"/>
                </Ellipse.RenderTransform>
            </Ellipse>
            <Ellipse Name="third_e3" Style="{StaticResource thirdStyle_Ellipse}">
                <Ellipse.RenderTransform>
                    <RotateTransform Angle="0"/>
                </Ellipse.RenderTransform>
            </Ellipse>
            <Ellipse Name="third_e4" Style="{StaticResource thirdStyle_Ellipse}" >
                <Ellipse.RenderTransform>
                    <RotateTransform Angle="0"/>
                </Ellipse.RenderTransform>
            </Ellipse>
            <Ellipse Name="third_e5" Style="{StaticResource thirdStyle_Ellipse}">
                <Ellipse.RenderTransform>
                    <RotateTransform Angle="0"/>
                </Ellipse.RenderTransform>
            </Ellipse>
        </Canvas>

二、动画故事板

cs 复制代码
 <Storyboard x:Key="third_sb" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" RepeatBehavior="Forever">
            <DoubleAnimation Storyboard.TargetName="third_e1" To="360" Duration="0:0:2"  EasingFunction="{StaticResource powerease}" AccelerationRatio="0.1" DecelerationRatio="0.9"/>
            <!--加速比 减速比-->
            <DoubleAnimation Storyboard.TargetName="third_e2" To="360" Duration="0:0:2" EasingFunction="{StaticResource powerease}" AccelerationRatio="0.3" DecelerationRatio="0.7"/>
            <DoubleAnimation Storyboard.TargetName="third_e3" To="360" Duration="0:0:2" EasingFunction="{StaticResource powerease}" AccelerationRatio="0.5" DecelerationRatio="0.5"/>
            <DoubleAnimation Storyboard.TargetName="third_e4" To="360" Duration="0:0:2" EasingFunction="{StaticResource powerease}" AccelerationRatio="0.7" DecelerationRatio="0.3"/>
            <DoubleAnimation Storyboard.TargetName="third_e5" To="360" Duration="0:0:2" EasingFunction="{StaticResource powerease}" AccelerationRatio="0.9" DecelerationRatio="0.1"/>
        </Storyboard>

三、外部样式

cs 复制代码
 <!--第三个动画圆的样式-->
 <Style x:Key="thirdStyle_Ellipse" TargetType="Ellipse">
     <Setter Property="Width" Value="25"/>
     <Setter Property="Height" Value="25"/>
     <Setter Property="Canvas.Left" Value="87.5"/>
     <Setter Property="Canvas.Top" Value="50"/>
     <Setter Property="Fill" Value="#0d3f67"/>
     <Setter Property="RenderTransformOrigin" Value="0.5,2"/>
 </Style>
相关推荐
nightunderblackcat25 分钟前
新手向:使用Python将多种图像格式统一转换为JPG
开发语言·python
我爱Jack40 分钟前
深入解析 LinkedList
java·开发语言
engchina1 小时前
Python PDF处理库深度对比:PyMuPDF、pypdfium2、pdfplumber、pdfminer的关系与区别
开发语言·python·pdf
拓端研究室1 小时前
专题:2025供应链数智化与效率提升报告|附100+份报告PDF、原数据表汇总下载
开发语言·php
一百天成为python专家1 小时前
python库之jieba 库
开发语言·人工智能·python·深度学习·机器学习·pycharm·python3.11
Go Dgg2 小时前
【Go + Gin 实现「双 Token」管理员登录】
开发语言·golang·gin
十五年专注C++开发2 小时前
hiredis: 一个轻量级、高性能的 C 语言 Redis 客户端库
开发语言·数据库·c++·redis·缓存
WJ.Polar2 小时前
Python数据容器-集合set
开发语言·python
晓13132 小时前
JavaScript加强篇——第七章 浏览器对象与存储要点
开发语言·javascript·ecmascript
nbsaas-boot2 小时前
Go语言生态成熟度分析:为何Go还无法像Java那样实现注解式框架?
java·开发语言·golang