当设置了owner的子窗口显示后,点击子窗口外部,需要一种反馈机制(反馈动画)。

实现:

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()),Value = 1.0});
scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = 0.95});
scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = 1.0}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = 1.0});
scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = 0.95});
scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),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()),Value = });
animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = });
animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds()),Value = }); Storyboard.SetTarget(animation, window);
Storyboard.SetTargetProperty(animation, new PropertyPath("(FrameworkElement.Effect).(DropShadowEffect.BlurRadius)")); _storyboard = new Storyboard
{
Children = new TimelineCollection { animation }
};

设置后,点击窗口外部,子窗口唤醒时,会有窗口外部阴影变化

关键字:模态窗口,窗口抖动,窗口阴影

WPF window 子窗口反馈效果(抖动/阴影渐变)的更多相关文章

  1. WPF Window异形窗口演示

    我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...

  2. .net4.6版本前设置window子窗口位置主窗口闪烁

    在安装了.net4.6的版本是不会出现该问题的,但是在4.6以下的版本会出现,当设置之窗体的left和top属性时,会让主窗体闪烁一下. 之前是在load事件下写的: child_window.loa ...

  3. WPF制作子窗体的弹出动画效果

    创建一个WPF应用程序WpfApplication1,新建个窗体DialogWin <Windowx:Class="WpfApplication1.DialogWin" xm ...

  4. 解决 WPF 嵌套的子窗口在改变窗口大小的时候闪烁的问题

    原文:解决 WPF 嵌套的子窗口在改变窗口大小的时候闪烁的问题 因为 Win32 的窗口句柄是可以跨进程传递的,所以可以用来实现跨进程 UI.不过,本文不会谈论跨进程 UI 的具体实现,只会提及其实现 ...

  5. 父窗口window.showModalDialog传值 子窗口window.returnValue返回值

    父窗口打开子窗口页面: var fatherWindow = document.all.dealReason;//想传的值 win = window.showModalDialog(strUrl, f ...

  6. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  7. js window.open() 父窗口与子窗口的互相调用(未必有用)

    javascript 父窗口与子窗口的互相调用 <html> <head></head> <body> 主要实现父子关系的页面 window.opene ...

  8. 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 //&&&&&&&&&&&&&&&&&&a ...

  9. WPF FileFolderDialog 和弹出子窗口的一些问题

    摘要:本文主要是WPF中 FileFolderDialog的相关问题,补充了关于在父窗口弹出子窗口,以及子窗口的相关属性(Data Binding)和命令绑定(Delegate Command)问题, ...

随机推荐

  1. vue的学习之路

    一.vs code中,适合vue的前端插件 查看网址:http://blog.csdn.net/caijunfen/article/details/78749766 二.如何使用git从gitub上拉 ...

  2. 微信小程序-自定义下拉刷新

    最近给别个公司做技术支持,要实现微信小程序上拉刷新与下拉加载更多 微信给出的接口不怎么友好,最终想实现效果类似QQ手机版 ,一共3种下拉刷新状态变化,文字+图片+背景颜色 最终实现后的效果(这里提示有 ...

  3. 使用node自动生成html并调用cmd命令提交代码到仓库

    生成html提交到git仓库 基于目前的express博客,写了一点代码,通过request模块来请求站点,将html保存到coding-pages目录,复制静态文件夹到coding-pages,最后 ...

  4. 快速找出网站中可能存在的XSS漏洞实践(一)

    一.背景 笔者最近在慕课录制了一套XSS跨站漏洞 加强Web安全视频教程,课程当中有讲到XSS的挖掘方式,所以在录制课程之前需要做大量实践案例,最近视频已经录制完成,准备将这些XSS漏洞的挖掘过程记录 ...

  5. Android JNI 学习(二):JNI 设计机制

    本章我们重点说明以下JNI设计的问题,本章中提到的大多数设计问题都与native方法有关.至于调用相关的API的设计,我们会在后面进行介绍. 一.JNI接口函数和指针 native 代码通过调用JNI ...

  6. git常用命令总结——你一定会用到的几个命令

    git入门看廖雪峰大神的教程即可,通俗易懂:      https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b806 ...

  7. LeetCode:1_Two_Sum | 两个元素相加等于目标元素 | Medium

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  8. 使用 IdentityServer4 实现 OAuth 2.0 与 OpenID Connect 服务

    IdentityServer4 是 ASP.NET Core 的一个包含 OIDC 和 OAuth 2.0 协议的框架.最近的关注点在 ABP 上,默认 ABP 也集成 IdentityServer4 ...

  9. Prometheus 入门与实践

    原文链接:https://www.ibm.com/developerworks/cn/cloud/library/cl-lo-prometheus-getting-started-and-practi ...

  10. MySQL高可用新玩法之MGR+Consul

    前面的文章有提到过利用consul+mha实现mysql的高可用,以及利用consul+sentinel实现redis的高可用,具体的请查看:http://www.cnblogs.com/gomysq ...