From 79dd879aa2cffdf9d423fcb52ebb898d2b50d3c0 Mon Sep 17 00:00:00 2001 From: Mike Corsaro Date: Fri, 12 Jul 2024 17:35:08 -0700 Subject: [PATCH] Don't throw exceptions on back-to-back window deactivations (#23519) * Don't throw exceptions on back-to-back window deactivations, as this is valid behavior on platforms such as Windows. * Switch activation logic check to be in MauiWinUIWindow * Clarify comment --------- Co-authored-by: Mike Corsaro --- src/Core/src/Platform/Windows/MauiWinUIWindow.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Core/src/Platform/Windows/MauiWinUIWindow.cs b/src/Core/src/Platform/Windows/MauiWinUIWindow.cs index 0e2bf22065a6..046498095271 100644 --- a/src/Core/src/Platform/Windows/MauiWinUIWindow.cs +++ b/src/Core/src/Platform/Windows/MauiWinUIWindow.cs @@ -75,6 +75,14 @@ protected virtual void OnActivated(object sender, UI.Xaml.WindowActivatedEventAr else _enableResumeEvent = true; } + else if (args.WindowActivationState == UI.Xaml.WindowActivationState.Deactivated && + !_isActivated) + { + // Don't invoke deactivated event if we're not activated. It's possible we can + // recieve this event multiple times if we start a new child process and that + // process creates a new window + return; + } else { _isActivated = false;