当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
CCF paper conference IEEE how to query all articles of a conference journal
多线程(基础) - 4万字总结
看我如何用多线程,帮助运营小姐姐解决数据校对系统变慢!
通过方法引用获取方法名
[kali-information collection] (1.9) Metasploit + search engine tool Shodan
Swift中什么时候不能用 () 代替 Void 来使用
学习经验分享之七:YOLOv5代码中文注释
SQL函数 TRIM
企业级数据治理工作怎么开展?Datahub这样做
Problem solving in the process of using mosquitto
Geoffery Hinton: The Next Big Thing in Deep Learning
基于threejs的商品VR展示平台的设计与实现思路
Multithreading (Basic) - 40,000 word summary
sva 断言资料
阿里云数据存储生态计划发布,助力伙伴数据创新
暑期总结3
从幻核疑似裁撤看如何保证NFT的安全
大疆P4M云遮挡矫正
【2022 小目标检测综述】Towards Large-Scale Small Object Detection: Survey and Benchmarks
一体化在线政务服务平台,小程序容器技术加速建设步伐