首页 > 代码库 > WPF window 子窗口反馈效果(拉动/渐变)
WPF window 子窗口反馈效果(拉动/渐变)
当子窗口显示后,点击子窗口外部,需要有反馈动画。
实现:
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 = http://www.mamicode.com/1.0}); scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = http://www.mamicode.com/0.9}); scaleXDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = http://www.mamicode.com/1.0}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)),Value = http://www.mamicode.com/1.0}); scaleYDoubleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),Value = http://www.mamicode.com/0.9}); 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 = http://www.mamicode.com/0}); animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)),Value = http://www.mamicode.com/50}); animation.KeyFrames.Add(new EasingDoubleKeyFrame{KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)),Value = http://www.mamicode.com/0}); Storyboard.SetTarget(animation, window); Storyboard.SetTargetProperty(animation, new PropertyPath("(FrameworkElement.Effect).(DropShadowEffect.BlurRadius)")); _storyboard = new Storyboard { Children = new TimelineCollection { animation } };
WPF window 子窗口反馈效果(拉动/渐变)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。