http://blog.csdn.net/lhx527099095/article/details/8005095

先上张效果图看看 如果不如您的法眼 可以移步了 或者有更好的效果 可以留言给我

废话不多说 直接贴代码 一个usercontrol

[csharp] view
plain
copy

  1. <UserControl x:Class="LoadingMask_Demo.LoadingWait"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. IsVisibleChanged="HandleVisibleChanged">
  6. <UserControl.Background>
  7. <SolidColorBrush Color="Black" Opacity="0.2"  />
  8. </UserControl.Background>
  9. <UserControl.Resources>
  10. <SolidColorBrush Color="#FF007BE5" x:Key="CirclesColor" />
  11. <!--<SolidColorBrush Color="Black" x:Key="BackgroundColor" Opacity=".20" />-->
  12. </UserControl.Resources>
  13. <Viewbox Width="100" Height="100"
  14. HorizontalAlignment="Center"
  15. VerticalAlignment="Center">
  16. <Grid x:Name="LayoutRoot"
  17. Background="Transparent"
  18. ToolTip="Please wait...."
  19. HorizontalAlignment="Center"
  20. VerticalAlignment="Center">
  21. <TextBlock Text="Loading..."  HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" Foreground="#FFE3953D" FontWeight="Bold" />
  22. <Canvas RenderTransformOrigin="0.5,0.5"
  23. HorizontalAlignment="Center"
  24. VerticalAlignment="Center" Width="120"
  25. Height="120" Loaded="HandleLoaded"
  26. Unloaded="HandleUnloaded"  >
  27. <Ellipse x:Name="C0" Width="20" Height="20"
  28. Canvas.Left="0"
  29. Canvas.Top="0" Stretch="Fill"
  30. Fill="{StaticResource CirclesColor}" Opacity="1.0"/>
  31. <Ellipse x:Name="C1" Width="20" Height="20"
  32. Canvas.Left="0"
  33. Canvas.Top="0" Stretch="Fill"
  34. Fill="{StaticResource CirclesColor}" Opacity="0.9"/>
  35. <Ellipse x:Name="C2" Width="20" Height="20"
  36. Canvas.Left="0"
  37. Canvas.Top="0" Stretch="Fill"
  38. Fill="{StaticResource CirclesColor}" Opacity="0.8"/>
  39. <Ellipse x:Name="C3" Width="20" Height="20"
  40. Canvas.Left="0"
  41. Canvas.Top="0" Stretch="Fill"
  42. Fill="{StaticResource CirclesColor}" Opacity="0.7"/>
  43. <Ellipse x:Name="C4" Width="20" Height="20"
  44. Canvas.Left="0"
  45. Canvas.Top="0" Stretch="Fill"
  46. Fill="{StaticResource CirclesColor}" Opacity="0.6"/>
  47. <Ellipse x:Name="C5" Width="20" Height="20"
  48. Canvas.Left="0"
  49. Canvas.Top="0" Stretch="Fill"
  50. Fill="{StaticResource CirclesColor}" Opacity="0.5"/>
  51. <Ellipse x:Name="C6" Width="20" Height="20"
  52. Canvas.Left="0"
  53. Canvas.Top="0" Stretch="Fill"
  54. Fill="{StaticResource CirclesColor}" Opacity="0.4"/>
  55. <Ellipse x:Name="C7" Width="20" Height="20"
  56. Canvas.Left="0"
  57. Canvas.Top="0" Stretch="Fill"
  58. Fill="{StaticResource CirclesColor}" Opacity="0.3"/>
  59. <Ellipse x:Name="C8" Width="20" Height="20"
  60. Canvas.Left="0"
  61. Canvas.Top="0" Stretch="Fill"
  62. Fill="{StaticResource CirclesColor}" Opacity="0.2"/>
  63. <Canvas.RenderTransform>
  64. <RotateTransform x:Name="SpinnerRotate"
  65. Angle="0" />
  66. </Canvas.RenderTransform>
  67. </Canvas>
  68. </Grid>
  69. </Viewbox>
  70. </UserControl>
  71. 后台代码:
  72. using System;
  73. using System.Collections.Generic;
  74. using System.Linq;
  75. using System.Text;
  76. using System.Windows;
  77. using System.Windows.Controls;
  78. using System.Windows.Data;
  79. using System.Windows.Documents;
  80. using System.Windows.Input;
  81. using System.Windows.Media;
  82. using System.Windows.Media.Imaging;
  83. using System.Windows.Navigation;
  84. using System.Windows.Shapes;
  85. using System.Windows.Threading;
  86. namespace LoadingMask_Demo
  87. {
  88. /// <summary>
  89. /// Interaction logic for LoadingWait.xaml
  90. /// </summary>
  91. public partial class LoadingWait : UserControl
  92. {
  93. #region Data
  94. private readonly DispatcherTimer animationTimer;
  95. #endregion
  96. #region Constructor
  97. public LoadingWait()
  98. {
  99. InitializeComponent();
  100. animationTimer = new DispatcherTimer(
  101. DispatcherPriority.ContextIdle, Dispatcher);
  102. animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 90);
  103. }
  104. #endregion
  105. #region Private Methods
  106. private void Start()
  107. {
  108. animationTimer.Tick += HandleAnimationTick;
  109. animationTimer.Start();
  110. }
  111. private void Stop()
  112. {
  113. animationTimer.Stop();
  114. animationTimer.Tick -= HandleAnimationTick;
  115. }
  116. private void HandleAnimationTick(object sender, EventArgs e)
  117. {
  118. SpinnerRotate.Angle = (SpinnerRotate.Angle + 36) % 360;
  119. }
  120. private void HandleLoaded(object sender, RoutedEventArgs e)
  121. {
  122. const double offset = Math.PI;
  123. const double step = Math.PI * 2 / 10.0;
  124. SetPosition(C0, offset, 0.0, step);
  125. SetPosition(C1, offset, 1.0, step);
  126. SetPosition(C2, offset, 2.0, step);
  127. SetPosition(C3, offset, 3.0, step);
  128. SetPosition(C4, offset, 4.0, step);
  129. SetPosition(C5, offset, 5.0, step);
  130. SetPosition(C6, offset, 6.0, step);
  131. SetPosition(C7, offset, 7.0, step);
  132. SetPosition(C8, offset, 8.0, step);
  133. }
  134. private void SetPosition(Ellipse ellipse, double offset,
  135. double posOffSet, double step)
  136. {
  137. ellipse.SetValue(Canvas.LeftProperty, 50.0
  138. + Math.Sin(offset + posOffSet * step) * 50.0);
  139. ellipse.SetValue(Canvas.TopProperty, 50
  140. + Math.Cos(offset + posOffSet * step) * 50.0);
  141. }
  142. private void HandleUnloaded(object sender, RoutedEventArgs e)
  143. {
  144. Stop();
  145. }
  146. private void HandleVisibleChanged(object sender,
  147. DependencyPropertyChangedEventArgs e)
  148. {
  149. bool isVisible = (bool)e.NewValue;
  150. if (isVisible)
  151. Start();
  152. else
  153. Stop();
  154. }
  155. #endregion
  156. }
  157. }

调用的代码也贴出来吧

[csharp] view
plain
copy

  1. <Window x:Class="LoadingMask_Demo.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow" Height="350" Width="525"
  5. xmlns:local="clr-namespace:LoadingMask_Demo"
  6. >
  7. <DockPanel>
  8. <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
  9. <Button  Content="show" Width="70" Height="30" Click="ShowButton_Click" />
  10. <Button  Content="hide" Width="70" Height="30" Click="HideButton_Click"/>
  11. </StackPanel>
  12. <Grid Background="#FF484848" DockPanel.Dock="Bottom">
  13. <TextBlock Text="asdfasdfasdf" Foreground="White"/>
  14. <local:LoadingWait x:Name="_loading"  Visibility="Collapsed"/>
  15. </Grid>
  16. </DockPanel>
  17. </Window>
  18. 后台代码
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows;
  24. using System.Windows.Controls;
  25. using System.Windows.Data;
  26. using System.Windows.Documents;
  27. using System.Windows.Input;
  28. using System.Windows.Media;
  29. using System.Windows.Media.Imaging;
  30. using System.Windows.Navigation;
  31. using System.Windows.Shapes;
  32. namespace LoadingMask_Demo
  33. {
  34. /// <summary>
  35. /// Interaction logic for MainWindow.xaml
  36. /// </summary>
  37. public partial class MainWindow : Window
  38. {
  39. public MainWindow()
  40. {
  41. InitializeComponent();
  42. }
  43. private void ShowButton_Click(object sender, RoutedEventArgs e)
  44. {
  45. this._loading.Visibility = Visibility.Visible;
  46. }
  47. private void HideButton_Click(object sender, RoutedEventArgs e)
  48. {
  49. this._loading.Visibility = Visibility.Collapsed;
  50. }
  51. }
  52. }

WPF 过渡效果的更多相关文章

  1. C# WPF过渡效果实现(C# WPF Material Design UI: Transitions)

    时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...

  2. Silverlight及WPF中实现自定义BusyIndicator

    在开发Silverlight或者WPF项目时,当我们调用Web服务来加载一些数据时,由于数据量比较大需要较长的时间,需要用户等待,为了给用户友好的提示和避免用户在加载数据过程中进行重复操作,我们通常使 ...

  3. wpf动画概述

    http://msdn.microsoft.com/zh-cn/library/vstudio/ms752312(v=vs.100).aspx Windows Presentation Foundat ...

  4. WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法。

    原文:WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/articl ...

  5. WPF中的动画——(五)关键帧动画

    与 From/To/By 动画类似,关键帧动画以也可以以动画形式显示目标属性值. 和From/To/By 动画不同的是, From/To/By 动画只能控制在两个状态之间变化,而关键帧动画则可以在多个 ...

  6. silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发)

    原文:silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发) 这章有点长,所以我分成了两章.这一章主要是准备工作,差不多算美工篇吧,这章基本不会介绍多少动画效果,主要讲 ...

  7. silverlight,WPF动画终极攻略之迟来的第三章 动画整合篇(Blend 4开发)

    原文:silverlight,WPF动画终极攻略之迟来的第三章 动画整合篇(Blend 4开发) 有个问题想请教下大家,我仿了腾讯的SL版QQ,相似度95%以上.我想写成教程教大家怎么开发出来,会不会 ...

  8. 【WPF学习】第五十三章 动画类型回顾

    创建动画面临的第一个挑战是为动画选择正确的属性.期望的结果(例如,在窗口中移动元素)与需要使用的属性(在这种情况下是Canvas.Left和Canvas.Top属性)之间的关系并不总是很直观.下面是一 ...

  9. 【WPF学习】第六十六章 支持可视化状态

    上一章介绍的ColorPicker控件,是控件设计的最好示例.因为其行为和可视化外观是精心分离的,所以其他设计人员可开发动态改变其外观的新模板. ColorPicker控件如此简单的一个原因是不涉及状 ...

随机推荐

  1. Python语法之用户交互与基本运算符

    一.与用户交互 1.接收用户输入 python3中的input会把用户输入的所有内容都存成str类型 age = input("请输入您的年龄: ") # "内容&quo ...

  2. Vue 实现微信提示浏览器转跳功能

    <template> <div class="main"> <div :class="show==true ? 'block':'block ...

  3. MATLAB—数组运算及数组化编程

    文章目录 前言 一.数组的结构和创建 1.数组及其结构 2.行数组的创建 3.对数组构造的操作 二.数组元素编址及寻访 1.数组元素的编址 2.二维数组元素的寻访 三.数组运算 非数的问题 前言 编程 ...

  4. 【现学现卖】th:href标签动态路径设置,thymeleaf获取session中的属性值

    update:2020-02-28:按道理来说这个功能在前后端分离的时候应该不怎么用的上,基本到现在我还是没遇到过有这样的需求,不过也是一种方法就是.th:href="@{/{role}/l ...

  5. Synchronized和ReentranLock的区别

    1.底层实现上来说? Synchronized是JVM层面的锁,是Java关键字,通过monitor对象来完成. ReentranLock是API层面的锁底层使用AQS. 2.是否可手动释放锁? sy ...

  6. 在docker安装tomcat的时候,报错:Caused by: java.lang.IllegalArgumentException: The AJP Connector is configured with secretRequired="true

    初识docker,试着在docker中安装tomcat(安装的tomcat8.5),并且挂载到宿主机的相关目录下,结果启动的时候报错: 12-May-2020 01:14:34.061 SEVERE ...

  7. Azkaban入门(启动一个Simple Example)

    Azkaban简介 azkaban是一个开源的任务调度系统 Azkaban是一套简单的任务调度服务,整体包括三部分webserver.dbserver.executorserver. 开发语言为Jav ...

  8. java 的内存结构

    Java内存结构详解 Java把内存分成:栈内存,堆内存,方法区,本地方法区和寄存器等. 下面分别介绍栈内存,堆内存,方法区各自一些特性: 1.栈内存 (1)一些基本类型的变量和对象的引用变量都是在函 ...

  9. javaWeb常用面试题

    JDBC JDBC访问数据库的基本步骤是什么? 加载驱动 通过DriverManager对象获取连接对象Connection 通过连接对象获取会话,有2种方式Statement.PreparedSta ...

  10. C++11 shared_ptr(智能指针)详解

    要确保用 new 动态分配的内存空间在程序的各条执行路径都能被释放是一件麻烦的事情.C++ 11 模板库的 <memory> 头文件中定义的智能指针,即 shared _ptr 模板,就是 ...