WPF window 子窗口反馈效果(抖动/渐变)
2017-08-14 20:29
435 查看
当子窗口显示后,点击子窗口外部,需要有反馈动画。
实现:
1.事件捕捉
每次点击子窗口外部,即母窗口时,事件捕捉如下
HwndSource hwndSource = PresentationSource.FromVisual(this.Owner) as HwndSource;//窗口过程
hwndSource?.AddHook(WndProc);
也可以调用WindowInteropHelper,获取母窗口句柄。
var hwnd = new WindowInteropHelper(this.Owner).Handle;
if (hwnd != IntPtr.Zero)
{
var hwndSource = HwndSource.FromHwnd(hwnd);
hwndSource?.AddHook(WndProc);
}
事件中,启动动画
2.动画设置
窗口抖动 动画
窗口阴影 动画
实现:
1.事件捕捉
每次点击子窗口外部,即母窗口时,事件捕捉如下
HwndSource hwndSource = PresentationSource.FromVisual(this.Owner) as HwndSource;//窗口过程
hwndSource?.AddHook(WndProc);
也可以调用WindowInteropHelper,获取母窗口句柄。
var hwnd = new WindowInteropHelper(this.Owner).Handle;
if (hwnd != IntPtr.Zero)
{
var hwndSource = HwndSource.FromHwnd(hwnd);
hwndSource?.AddHook(WndProc);
}
事件中,启动动画
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg != 0x20) return IntPtr.Zero; if (lParam.ToInt32() == 0x201fffe) _storyboard?.Begin(); return IntPtr.Zero; }
2.动画设置
窗口抖动 动画
var scaleXDoubleAnimation = new DoubleAnimationUsingKeyFrames(); var scaleYDoubleAnimation = new DoubleAnimationUsingKeyFrames(); scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 1.0}); scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = 0.95}); scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = 1.0}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 1.0}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = 0.95}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = 1.0}); Storyboard.SetTarget(scaleXDoubleAnimation, window); Storyboard.SetTarget(scaleYDoubleAnimation, window); Storyboard.SetTargetProperty(scaleXDoubleAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)")); Storyboard.SetTargetProperty(scaleYDoubleAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)")); _storyboard = new Storyboard{Children =new TimelineCollection { scaleXDoubleAnimation, scaleYDoubleAnimation }};
窗口阴影 动画
var animation = new DoubleAnimationUsingKeyFrames(); animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = 0}); animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = 50}); animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)),Value = 0}); Storyboard.SetTarget(animation, window); Storyboard.SetTargetProperty(animation, new PropertyPath("(FrameworkElement.Effect).(DropShadowEffect.BlurRadius)")); _storyboard = new Storyboard { Children = new TimelineCollection { animation } };
相关文章推荐
- WPF实现渐变淡入淡出的登陆窗口效果
- WPF示例-1-渐变效果
- 好玩的WPF第一弹:窗口抖动+边框阴影效果+倒计时显示文字
- WPF 字体阴影及渐变字效果示例代码
- wpf 控件的抖动效果
- 好玩的WPF第一弹:窗口抖动+边框阴影效果+倒计时显示文字
- WPF实现渐变淡入淡出的动画效果
- 在WPF中模拟SL的ChildWindow效果
- WPF实现渐变淡入淡出的登陆窗口效果
- 浏览器实现颜色渐变效果(兼容)
- TextView显示文字过长时添加阴影渐变消失效果
- WPF WebBrowser屏蔽弹出alert ,confirm ,prompt ,showModalDialog() ,window.open()
- WPFwindow窗体的关闭事件Closing 和Closed
- WPF,Silverlight与XAML读书笔记第三十四 - 可视化效果之2D变换
- Delphi DbGridEh实现表格没有内容的渐变效果
- 代码抖动IOS 仿网易 banner scrollview 到头后 手势 事件提交到下级 拉开界面的效果
- CSS实现兼容性的渐变背景(gradient)效果
- 一个模仿图片透明渐变做的表格颜色渐变效果