当前位置:网站首页>WPF 实现窗体抖动效果
WPF 实现窗体抖动效果
2022-08-02 11:31:00 【yanjinhua】
实现窗体抖动效果仿QQ窗体抖动
窗体抖动使用 DoubleAnimation修改窗体的当前Left的+15,并设置AutoReverse=True该值指示时间线在完成向前迭代后是否按相反的顺序播放RepeatBehavior默认值为Count 1,表示时间线播放一次。FillBehavior属性设置Stop. 由于其填充期中的动画继续重写其目标属性的值,因此尝试通过其他方式设置目标属性的值似乎不起作用;
1)WindowShake.cs 代码如下;
public static void WindowShake(Window window = null)
{
if (window == null)
if (Application.Current.Windows.Count > 0)
window = Application.Current.Windows.OfType<Window>().FirstOrDefault(o => o.IsActive);
var doubleAnimation = new DoubleAnimation
{
From = window.Left,
To = window.Left + 15,
Duration = TimeSpan.FromMilliseconds(50),
AutoReverse = true,
RepeatBehavior = new RepeatBehavior(3),
FillBehavior = FillBehavior.Stop
};
window.BeginAnimation(Window.LeftProperty, doubleAnimation);
var wavUri = new Uri(@"pack://application:,,,/WPFDevelopers;component/Resources/Audio/shake.wav");
var streamResource = Application.GetResourceStream(wavUri);
var player1 = new SoundPlayer(streamResource.Stream);
player1.Play();
}
2)Shake 使用代码如下;
方式一:不传 Window参的话,获取当前程序运行存在焦点的Window;
ControlsHelper.WindowShake();
方式二:可以传递需要抖动的 Window;
ControlsHelper.WindowShake(window);
Timeline 类Gtihub[1]Gitee[2]
参考资料
Gtihub: https://github.com/WPFDevelopersOrg/WPFDevelopers
[2]gitee: https://gitee.com/WPFDevelopersOrg/WPFDevelopers
边栏推荐
- SQL 经典50题(题目+解答)(1)
- idea常用插件
- npm run serve启动报错npm ERR Missing script “serve“
- SQL函数 $TRANSLATE
- 字母交换--字符串dp
- npm WARN deprecated [email protected] This version of tar is no longer supported, and will not receive
- 故障分析 | 一条 SELECT 语句跑崩了 MySQL ,怎么回事?
- 华为eNSP(基础实验通信)
- The sitcom "Re-Walking the Long March" was staged
- SQL 数据更新
猜你喜欢
[email protected] This version of tar is no longer supported, and will not receive"/>npm WARN deprecated [email protected] This version of tar is no longer supported, and will not receive

What is the future of smartwatches?

基于深度学习的裂缝检测技术

Mysql transaction isolation level and MVCC (multi-version concurrency control)

使用kubesphere图形界面创建一个devops的CI/CD流程

yolo格式(txt)数据集转VOC(xml)

翁恺C语言程序设计网课笔记合集
![[kali-information collection] (1.9) Metasploit + search engine tool Shodan](/img/d2/6fae03d7597daa908a6816abc34e04.png)
[kali-information collection] (1.9) Metasploit + search engine tool Shodan

npm run dev 和 npm run serve区别

Swift中什么时候不能用 () 代替 Void 来使用
随机推荐
当POC遇见RPA:RPA项目顺利实施的关键
C#为listview选中的项添加右键菜单
yolo格式(txt)数据集转VOC(xml)
Idea 全局搜索(idea如何全局搜索关键字)
21 Days Learning Challenge - Day 1 Punch (Screen Density)
mysql清除binlog日志文件
Several reasons why applet plugins benefit developers
Create an application operation process using the kubesphere GUI
pyqt5连接MYSQL数据库问题
大疆P4M云遮挡矫正
划分训练集,验证集,测试集
AdguardHome如何配置设置?我的AdguardHome配置内容过滤器拦截列表
Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
基于threejs的商品VR展示平台的设计与实现思路
ECCV22|PromptDet:无需手动标注,迈向开放词汇的目标检测
Shell编程之条件语句
打破千篇一律,DIY属于自己独一无二的商城
ASP.NET Core 6框架揭秘实例演示[31]:路由&quot;高阶&quot;用法
5G网络切片技术
npm run serve启动报错npm ERR Missing script “serve“