手把手教你 用 wpf 制作metro ProgressRing (Windows8 等待动画)
效果图:

还在羡慕metro的ProgressRing吗?
wpf 也可以拥有
首先说下思路,
一共6个点围绕一直圆转,所以需要使用rotation动画 并且一直转下去。
那么下面的问题就好解决了。
首先是xaml 部分
我们需要实现旋转动画:
所以要用到这个:
- <DoubleAnimationUsingKeyFrames
- Storyboard.TargetProperty="(Ellipse.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
- <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
- <EasingDoubleKeyFrame Value="90" KeyTime="0:0:0.2">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="270" KeyTime="0:0:1.6">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="450" KeyTime="0:0:1.8">
- </EasingDoubleKeyFrame>
- <LinearDoubleKeyFrame Value="630" KeyTime="0:0:3.2"/>
- <EasingDoubleKeyFrame Value="720" KeyTime="0:0:3.4">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="720" KeyTime="0:0:5.0">
- </EasingDoubleKeyFrame>
- </DoubleAnimationUsingKeyFrames>
上面这一段是单个ellipse的运动轨迹,当然你需要在属性中设置他的中心点值
代码如下:
- <Ellipse x:Name="el" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" >
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
接下来的事情就好办了,我们需要他转1圈就消失 结束后也消失,所以需要控制透明度,
- <DoubleAnimationUsingKeyFrames
- Storyboard.TargetProperty="Opacity">
- <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:0.2">
- <EasingDoubleKeyFrame.EasingFunction>
- <BackEase EasingMode="EaseInOut"/>
- </EasingDoubleKeyFrame.EasingFunction>
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:1.6">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:1.8">
- </EasingDoubleKeyFrame>
- <LinearDoubleKeyFrame Value="1" KeyTime="0:0:3.2"/>
- <EasingDoubleKeyFrame Value="0" KeyTime="0:0:3.5">
- <EasingDoubleKeyFrame.EasingFunction>
- <BackEase EasingMode="EaseOut"/>
- </EasingDoubleKeyFrame.EasingFunction>
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="0" KeyTime="0:0:5.0">
- </EasingDoubleKeyFrame>
- </DoubleAnimationUsingKeyFrames>
最终把一个圆变成多个圆的工作 就交给代码了,需要一点点小技巧 以下使用.net 4.5实现 其他版本可以吧Task.Delay 替换成Thread.Sleep
- <UserControl
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
- xmlns:local="clr-namespace:Transvalue.MetroStyleBusyIndicator"
- x:Class="Transvalue.MetroStyleBusyIndicator.MetroRotaionIndicator"
- mc:Ignorable="d"
- d:DesignHeight="300" d:DesignWidth="300">
- <UserControl.Resources>
- <Storyboard x:Key="Trans" RepeatBehavior="Forever">
- <DoubleAnimationUsingKeyFrames
- Storyboard.TargetProperty="(Ellipse.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
- <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
- <EasingDoubleKeyFrame Value="90" KeyTime="0:0:0.2">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="270" KeyTime="0:0:1.6">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="450" KeyTime="0:0:1.8">
- </EasingDoubleKeyFrame>
- <LinearDoubleKeyFrame Value="630" KeyTime="0:0:3.2"/>
- <EasingDoubleKeyFrame Value="720" KeyTime="0:0:3.4">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="720" KeyTime="0:0:5.0">
- </EasingDoubleKeyFrame>
- </DoubleAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames
- Storyboard.TargetProperty="Opacity">
- <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:0.2">
- <EasingDoubleKeyFrame.EasingFunction>
- <BackEase EasingMode="EaseInOut"/>
- </EasingDoubleKeyFrame.EasingFunction>
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:1.6">
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="1" KeyTime="0:0:1.8">
- </EasingDoubleKeyFrame>
- <LinearDoubleKeyFrame Value="1" KeyTime="0:0:3.2"/>
- <EasingDoubleKeyFrame Value="0" KeyTime="0:0:3.5">
- <EasingDoubleKeyFrame.EasingFunction>
- <BackEase EasingMode="EaseOut"/>
- </EasingDoubleKeyFrame.EasingFunction>
- </EasingDoubleKeyFrame>
- <EasingDoubleKeyFrame Value="0" KeyTime="0:0:5.0">
- </EasingDoubleKeyFrame>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </UserControl.Resources>
- <Canvas>
- <Ellipse x:Name="el" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" >
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- <Ellipse x:Name="el2" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" Opacity="0" >
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- <Ellipse x:Name="el3" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" Opacity="0">
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- <Ellipse x:Name="el4" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" Opacity="0">
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- <Ellipse x:Name="el5" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" Opacity="0">
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- <Ellipse x:Name="el6" Width="10" Height="10" Fill="White" Canvas.Left="73" Canvas.Top="57" Opacity="0">
- <Ellipse.RenderTransform>
- <TransformGroup>
- <ScaleTransform/>
- <SkewTransform/>
- <RotateTransform CenterX="-20" CenterY="-40"/>
- <TranslateTransform/>
- </TransformGroup>
- </Ellipse.RenderTransform>
- </Ellipse>
- </Canvas>
- </UserControl>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Transvalue.MetroStyleBusyIndicator
- {
- /// <summary>
- /// MetroRotaionIndicator.xaml 的交互逻辑
- /// </summary>
- public partial class MetroRotaionIndicator : UserControl
- {
- Storyboard trans;
- public MetroRotaionIndicator()
- {
- InitializeComponent();
- trans = Resources["Trans"] as Storyboard;
- this.Loaded += ((sender, e) =>
- {
- Active();
- });
- }
- public async void Active()
- {
- el.BeginStoryboard(trans);
- await Task.Delay(170);
- el2.BeginStoryboard(trans);
- await Task.Delay(170);
- el3.BeginStoryboard(trans);
- await Task.Delay(170);
- el4.BeginStoryboard(trans);
- await Task.Delay(170);
- el5.BeginStoryboard(trans);
- await Task.Delay(170);
- el6.BeginStoryboard(trans);
- }
- public void Stop()
- {
- trans.Stop(el);
- trans.Stop(el2);
- trans.Stop(el3);
- trans.Stop(el4);
- trans.Stop(el5);
- trans.Stop(el6);
- }
- }
- }
将以上内容编译成用户控件即可使用。
xmlns:MetroStyleBusyIndicator="clr-namespace:Transvalue.MetroStyleBusyIndicator;assembly=Transvalue.MetroStyleBusyIndicator"
<MetroStyleBusyIndicator:MetroRotaionIndicator HorizontalAlignment="Left" Height="187" Margin="924,534,0,0" VerticalAlignment="Top" Width="217"/>
手把手教你 用 wpf 制作metro ProgressRing (Windows8 等待动画)的更多相关文章
- [Swift通天遁地]一、超级工具-(11)使用EZLoadingActivity制作Loading加载等待动画
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 详解用CSS3制作圆形滚动进度条动画效果
主 题 今天手把手教大家用CSS3制作圆形滚动进度条动画,想不会都难!那么,到底是什么东东呢?先不急,之前我分享了一个css实现进度条效果的博客<CSS实现进度条和订单进度条>,但是呢, ...
- 手把手教你制作AppPreview视频并上传到appStore进行审核
手把手教你制作AppPreview视频并上传到appStore进行审核 注意,你需要使用iMovie才能够制作AppPreview视频文件,用QuickTime录制的无效! 最终效果 1. 新建一个事 ...
- PWA入门:手把手教你制作一个PWA应用
摘要: PWA图文教程 原文:PWA入门:手把手教你制作一个PWA应用 作者:MudOnTire Fundebug经授权转载,版权归原作者所有. 简介 Web前端的同学是否想过学习app开发,以弥补自 ...
- 手把手教你去ECSHOP版权 powered by ecshop
各位朋友大家好,欢迎来到ecshop开发中心系列视频教程:ecshop去版权.去版权是一种很常见的问题,有很多客户提到ECSHOP如何去版权?怎样去得干净.去得彻底?今天,ECSHOP开发中心手把 ...
- 手把手教你ranorex_android自动化测试第一个示例
要说android的自动化,那真是折腾死我了,从早期的monkeyrunner,到后来的robotium,再到最新的uiautomator,各有各的问题,总之性价比都不够高,不太适合我的使用场景.于是 ...
- C#:手把手教你用C#打包应用程序(安装程序卸载程序)
摘要:本文介绍在C#中手把手教你用C#打包应用程序(安装程序卸载程序) 1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点 ...
- 手把手教你玩转CSS3 3D技术
手把手教你玩转 CSS3 3D 技术 要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上 ...
- 手把手教你DIY尼康ML-L3红外遥控器
项目介绍 ML-L3是用于尼康部分型号相机的无线红外遥控器,可以通过红外方式来控制快门的释放,支持B门拍摄.官方售价100RMB左右,山寨版售价10RMB左右.虽然也能实现基本的遥控功能,但是功能还是 ...
随机推荐
- C# params关键字
params数组的要点 C#开发语言中 params 是关键字,可以指定在参数数目可变处采用参数的方法参数.在函数的参数数目可变而执行的代码差异很小的时候很有用! class Program { st ...
- poj1258 Agri-Net 最小生成树
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44032 Accepted: 18001 Descri ...
- PHP快速抓取快递信息
<?php header("Content-type:text/html;charset=utf-8"); /** * Express.class.php 快递查询类 * @ ...
- android menu showAsAction属性
app中有一个菜单(menu),showAsAction主要是针对这个菜单的显示起作用的,它有三个可选项:always:总是显示在界面上 never:不显示在界面上,只让出现在右边的三个点中 ifRo ...
- jlink安装
https://www.segger.com/jlink-software.html?step=1&file=JLink_510p
- canvas实践小实例二 —— 扇形
俗话说:发图不留种,菊花万人捅!我这里想延伸一下:教学不给例,说你是傻逼!哎呀,还挺押韵,嘻嘻,开个玩笑! 我们都讲了四期API的知识了,估计大家看的也是枯燥的很啊,前面的小实例也是太简单,简直不解渴 ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
- July 20th, Week 30th Wednesday, 2016
Learn from yesterday, live for today, and hope for tomorrow. 借鉴昨天,活着当下,憧憬未来. Yesterday is the past, ...
- Floyd最短路算法
Floyd最短路算法 ----转自啊哈磊[坐在马桶上看算法]算法6:只有五行的Floyd最短路算法 暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,如下图.为了节省经费以及方便计 ...
- 谈谈Objective-C的警告 (转)
原文地址:http://onevcat.com/2013/05/talk-about-warning/ 一个有节操的程序员会在乎自己的代码的警告,就像在乎饭碗边上有只死蟑螂那样. ——@onevcat ...