WPF 实现Loading自定义控件

5 篇文章 0 订阅

先上效果图

其实就是用动画实现的,然后滑动的速度用时间差来控制,

上源码吧,看不懂的评论区提问:

<UserControl
    x:Class="MyControl.UC_Loading"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:MyControl"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Width="110"
    Height="30"
    mc:Ignorable="d">
    <Grid>

        <Path
            x:Name="three"
            Width="24"
            Height="14"
            Margin="0,0,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Data="M264 235c-110.5 0-200 89.5-200 200v354h696c110.5 0 200-89.5 200-200V235H264z"
            Fill="#238b83"
            Opacity="0.6"
            Stretch="Fill" />
        <Path
            x:Name="two"
            Width="24"
            Height="14"
            Margin="0,0,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Data="M264 235c-110.5 0-200 89.5-200 200v354h696c110.5 0 200-89.5 200-200V235H264z"
            Fill="#238b83"
            Opacity="0.7"
            Stretch="Fill" />
        <Path
            x:Name="one"
            Width="26"
            Height="18"
            Margin="0,0,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Data="M264 235c-110.5 0-200 89.5-200 200v354h696c110.5 0 200-89.5 200-200V235H264z"
            Fill="#238b83"
            Opacity="1"
            Stretch="Fill" />
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Grid.Loaded">
                <BeginStoryboard>
                    <Storyboard RepeatBehavior="Forever">
                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:0.00000"
                            Storyboard.TargetName="one"
                            Storyboard.TargetProperty="Margin"
                            To="84,0,0,0"
                            Duration="0:0:0.8" />
                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:0.26"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Margin"
                            To="86,0,0,0"
                            Duration="0:0:0.8" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:0.6"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Opacity"
                            To="0.3"
                            Duration="0:0:0.6" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:1.5"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Opacity"
                            To="0.9"
                            Duration="0:0:0.001" />
                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:0.5"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Margin"
                            To="86,0,0,0"
                            Duration="0:0:1" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:0.7"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Opacity"
                            To="0.3"
                            Duration="0:0:0.7" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:1.5"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Opacity"
                            To="0.9"
                            Duration="0:0:0.001" />

                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:1.8"
                            Storyboard.TargetName="one"
                            Storyboard.TargetProperty="Margin"
                            To="0,0,0,0"
                            Duration="0:0:0.8" />
                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:2.07"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Margin"
                            To="0,0,0,0"
                            Duration="0:0:0.8" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:2.46"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Opacity"
                            To="0.3"
                            Duration="0:0:0.4" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:2.7"
                            Storyboard.TargetName="two"
                            Storyboard.TargetProperty="Opacity"
                            To="0.9"
                            Duration="0:0:0.001" />
                        <ThicknessAnimation
                            AutoReverse="False"
                            BeginTime="0:0:2.3"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Margin"
                            To="0,0,0,0"
                            Duration="0:0:1" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:2.6"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Opacity"
                            To="0.3"
                            Duration="0:0:0.3" />
                        <DoubleAnimation
                            AutoReverse="False"
                            BeginTime="0:0:3.3"
                            Storyboard.TargetName="three"
                            Storyboard.TargetProperty="Opacity"
                            To="0.9"
                            Duration="0:0:0.001" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
    </Grid>
</UserControl>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Rotion_深

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

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

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

打赏作者

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

抵扣说明:

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

余额充值