WPF 过渡效果
http://blog.csdn.net/lhx527099095/article/details/8005095
先上张效果图看看 如果不如您的法眼 可以移步了 或者有更好的效果 可以留言给我
废话不多说 直接贴代码 一个usercontrol
- <UserControl x:Class="LoadingMask_Demo.LoadingWait"
- 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"
- IsVisibleChanged="HandleVisibleChanged">
- <UserControl.Background>
- <SolidColorBrush Color="Black" Opacity="0.2" />
- </UserControl.Background>
- <UserControl.Resources>
- <SolidColorBrush Color="#FF007BE5" x:Key="CirclesColor" />
- <!--<SolidColorBrush Color="Black" x:Key="BackgroundColor" Opacity=".20" />-->
- </UserControl.Resources>
- <Viewbox Width="100" Height="100"
- HorizontalAlignment="Center"
- VerticalAlignment="Center">
- <Grid x:Name="LayoutRoot"
- Background="Transparent"
- ToolTip="Please wait...."
- HorizontalAlignment="Center"
- VerticalAlignment="Center">
- <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" Foreground="#FFE3953D" FontWeight="Bold" />
- <Canvas RenderTransformOrigin="0.5,0.5"
- HorizontalAlignment="Center"
- VerticalAlignment="Center" Width="120"
- Height="120" Loaded="HandleLoaded"
- Unloaded="HandleUnloaded" >
- <Ellipse x:Name="C0" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="1.0"/>
- <Ellipse x:Name="C1" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.9"/>
- <Ellipse x:Name="C2" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.8"/>
- <Ellipse x:Name="C3" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.7"/>
- <Ellipse x:Name="C4" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.6"/>
- <Ellipse x:Name="C5" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.5"/>
- <Ellipse x:Name="C6" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.4"/>
- <Ellipse x:Name="C7" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.3"/>
- <Ellipse x:Name="C8" Width="20" Height="20"
- Canvas.Left="0"
- Canvas.Top="0" Stretch="Fill"
- Fill="{StaticResource CirclesColor}" Opacity="0.2"/>
- <Canvas.RenderTransform>
- <RotateTransform x:Name="SpinnerRotate"
- Angle="0" />
- </Canvas.RenderTransform>
- </Canvas>
- </Grid>
- </Viewbox>
- </UserControl>
- 后台代码:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- namespace LoadingMask_Demo
- {
- /// <summary>
- /// Interaction logic for LoadingWait.xaml
- /// </summary>
- public partial class LoadingWait : UserControl
- {
- #region Data
- private readonly DispatcherTimer animationTimer;
- #endregion
- #region Constructor
- public LoadingWait()
- {
- InitializeComponent();
- animationTimer = new DispatcherTimer(
- DispatcherPriority.ContextIdle, Dispatcher);
- animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 90);
- }
- #endregion
- #region Private Methods
- private void Start()
- {
- animationTimer.Tick += HandleAnimationTick;
- animationTimer.Start();
- }
- private void Stop()
- {
- animationTimer.Stop();
- animationTimer.Tick -= HandleAnimationTick;
- }
- private void HandleAnimationTick(object sender, EventArgs e)
- {
- SpinnerRotate.Angle = (SpinnerRotate.Angle + 36) % 360;
- }
- private void HandleLoaded(object sender, RoutedEventArgs e)
- {
- const double offset = Math.PI;
- const double step = Math.PI * 2 / 10.0;
- SetPosition(C0, offset, 0.0, step);
- SetPosition(C1, offset, 1.0, step);
- SetPosition(C2, offset, 2.0, step);
- SetPosition(C3, offset, 3.0, step);
- SetPosition(C4, offset, 4.0, step);
- SetPosition(C5, offset, 5.0, step);
- SetPosition(C6, offset, 6.0, step);
- SetPosition(C7, offset, 7.0, step);
- SetPosition(C8, offset, 8.0, step);
- }
- private void SetPosition(Ellipse ellipse, double offset,
- double posOffSet, double step)
- {
- ellipse.SetValue(Canvas.LeftProperty, 50.0
- + Math.Sin(offset + posOffSet * step) * 50.0);
- ellipse.SetValue(Canvas.TopProperty, 50
- + Math.Cos(offset + posOffSet * step) * 50.0);
- }
- private void HandleUnloaded(object sender, RoutedEventArgs e)
- {
- Stop();
- }
- private void HandleVisibleChanged(object sender,
- DependencyPropertyChangedEventArgs e)
- {
- bool isVisible = (bool)e.NewValue;
- if (isVisible)
- Start();
- else
- Stop();
- }
- #endregion
- }
- }
调用的代码也贴出来吧
- <Window x:Class="LoadingMask_Demo.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="525"
- xmlns:local="clr-namespace:LoadingMask_Demo"
- >
- <DockPanel>
- <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
- <Button Content="show" Width="70" Height="30" Click="ShowButton_Click" />
- <Button Content="hide" Width="70" Height="30" Click="HideButton_Click"/>
- </StackPanel>
- <Grid Background="#FF484848" DockPanel.Dock="Bottom">
- <TextBlock Text="asdfasdfasdf" Foreground="White"/>
- <local:LoadingWait x:Name="_loading" Visibility="Collapsed"/>
- </Grid>
- </DockPanel>
- </Window>
- 后台代码
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace LoadingMask_Demo
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void ShowButton_Click(object sender, RoutedEventArgs e)
- {
- this._loading.Visibility = Visibility.Visible;
- }
- private void HideButton_Click(object sender, RoutedEventArgs e)
- {
- this._loading.Visibility = Visibility.Collapsed;
- }
- }
- }
WPF 过渡效果的更多相关文章
- C# WPF过渡效果实现(C# WPF Material Design UI: Transitions)
时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...
- Silverlight及WPF中实现自定义BusyIndicator
在开发Silverlight或者WPF项目时,当我们调用Web服务来加载一些数据时,由于数据量比较大需要较长的时间,需要用户等待,为了给用户友好的提示和避免用户在加载数据过程中进行重复操作,我们通常使 ...
- wpf动画概述
http://msdn.microsoft.com/zh-cn/library/vstudio/ms752312(v=vs.100).aspx Windows Presentation Foundat ...
- WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法。
原文:WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/articl ...
- WPF中的动画——(五)关键帧动画
与 From/To/By 动画类似,关键帧动画以也可以以动画形式显示目标属性值. 和From/To/By 动画不同的是, From/To/By 动画只能控制在两个状态之间变化,而关键帧动画则可以在多个 ...
- silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发)
原文:silverlight,WPF动画终极攻略之白云飘,坐车去旅游篇(Blend 4开发) 这章有点长,所以我分成了两章.这一章主要是准备工作,差不多算美工篇吧,这章基本不会介绍多少动画效果,主要讲 ...
- silverlight,WPF动画终极攻略之迟来的第三章 动画整合篇(Blend 4开发)
原文:silverlight,WPF动画终极攻略之迟来的第三章 动画整合篇(Blend 4开发) 有个问题想请教下大家,我仿了腾讯的SL版QQ,相似度95%以上.我想写成教程教大家怎么开发出来,会不会 ...
- 【WPF学习】第五十三章 动画类型回顾
创建动画面临的第一个挑战是为动画选择正确的属性.期望的结果(例如,在窗口中移动元素)与需要使用的属性(在这种情况下是Canvas.Left和Canvas.Top属性)之间的关系并不总是很直观.下面是一 ...
- 【WPF学习】第六十六章 支持可视化状态
上一章介绍的ColorPicker控件,是控件设计的最好示例.因为其行为和可视化外观是精心分离的,所以其他设计人员可开发动态改变其外观的新模板. ColorPicker控件如此简单的一个原因是不涉及状 ...
随机推荐
- 安装CDH6.2 agent报错
界面报错信息提示如下: file /opt/cloudera/parcels/.flood/CDH-6.2.0-1.cdh6.2.0.p0.967373-el7.parcel...does not e ...
- 手工设置Eclipse文本编辑器的配色
Eclipse中不同的文件都有自己专门的编辑器配色设置,下面分别说明. 文本编辑器的背景色: Window->Preferences-> General->Editors->T ...
- 【Java】@Scheduled常用的注解的使用
@Scheduled注解的使用 cron cron这个参数必须要接受一个cron表达式 cron表达式是个啥呢,Cron表达式是一个具有时间含义的字符串,字符串以5个空格隔开,分为6个域,格式为 X ...
- 备战秋招之十大排序——O(nlogn)级排序算法
时间复杂度O(nlogn)级排序算法 五.希尔排序 首批将时间复杂度降到 O(n^2) 以下的算法之一.虽然原始的希尔排序最坏时间复杂度仍然是O(n^2),但经过优化的希尔排序可以达到 O(n^{1. ...
- Java社区——个人项目开发笔记(二)
1.B\S架构通信原理 浏览器,服务器之间产生通信,浏览器访问服务器,服务器返回一个HTML,浏览器会对HTML进行解析,并渲染相关的内容. 在解析过程中,会发现HTML里引用了css文件,js文件, ...
- SpringBoot和mybatis整合报错:Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 152; columnNumber: 10; 元素类型为 "mapper"
很明显,报错是xml有问题,于是去检查,发现: 由于粗心,保存的时候,按的太频繁,多按了个s在里面,导致启动报错!
- k8s 执行 ingress yaml 文件报错: error when creating "ingress-myapp.yaml": Internal error occurred: failed calling webhook
k8s 执行 ingress yaml 文件报错:错误如下: [root@k8s-master01 baremetal]# kubectl apply -f ingress-test.yaml Err ...
- .Net Core 踩坑记录--程序独立发布 无法运行
背景 创建.net Core3.1 的Console程序 点击发布 选择独立部署模式 目标电脑 Win10 x64 未安装任何.Net SDK 现象 发布的程序 点击运行没有反应 或是直接闪退 解决 ...
- 异步编程之APM
一.APM概述 APM即异步编程模型的简写(Asynchronous Programming Model),我们平时经常会遇到类似BeginXXX和EndXXX的方法,我们在使用这些方法的时候,其实就 ...
- java web课程设计(简单商城的前后端双系统,基于maven三模块开发)
1.系统分析 1.1需求分析 实现一个简单但功能完整的商城项目,从设计到实现,规范化完成该项目,锻炼javaweb项目的编写能力,理解软件工程的软件设计思想 1.2编程技术简介 本次课程主要使用的软件 ...