From 4d72f1f9210503c9e988eaf6832a0267b8b2c838 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Wed, 21 Apr 2021 22:34:00 +0800 Subject: [PATCH] Update MessageBox.cs --- .../Controls/Window/MessageBox.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs b/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs index adfd8784..25af6967 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs @@ -50,6 +50,8 @@ namespace HandyControl.Controls private bool _showNo; + private IntPtr _lastActiveWindowIntPtr; + public static readonly DependencyProperty MessageProperty = DependencyProperty.Register( "Message", typeof(string), typeof(MessageBox), new PropertyMetadata(default(string))); @@ -127,6 +129,16 @@ namespace HandyControl.Controls } base.OnSourceInitialized(e); + + _lastActiveWindowIntPtr = InteropMethods.GetForegroundWindow(); + Activate(); + } + + protected override void OnClosed(EventArgs e) + { + InteropMethods.SetForegroundWindow(_lastActiveWindowIntPtr); + + base.OnClosed(e); } public override void OnApplyTemplate()