From 39b49e7aa18333f13db8e313df476a4861ad4c27 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Wed, 26 Jun 2024 12:07:17 -0700 Subject: [PATCH] Wpf: Fix startup when attaching to a WPF application --- src/Eto.Wpf/Forms/ApplicationHandler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Eto.Wpf/Forms/ApplicationHandler.cs b/src/Eto.Wpf/Forms/ApplicationHandler.cs index 8fdcbec11e..35e518c8bf 100755 --- a/src/Eto.Wpf/Forms/ApplicationHandler.cs +++ b/src/Eto.Wpf/Forms/ApplicationHandler.cs @@ -88,6 +88,11 @@ protected override void Initialize() { Control = new sw.Application { ShutdownMode = sw.ShutdownMode.OnExplicitShutdown }; sw.Forms.Application.EnableVisualStyles(); + Control.Startup += (s, e) => HandleStartup(); + } + else + { + HandleStartup(); } // Prevent race condition with volatile font collection field in WPF when measuring a window the first time @@ -97,7 +102,6 @@ protected override void Initialize() dispatcher = sw.Application.Current.Dispatcher ?? Dispatcher.CurrentDispatcher; instance = this; - Control.Startup += HandleStartup; ApplyThemes(); base.Initialize(); } @@ -114,7 +118,7 @@ void OnCurrentDomainUnhandledException(object sender, System.UnhandledExceptionE Callback.OnUnhandledException(Widget, unhandledExceptionArgs); } - void HandleStartup(object sender, sw.StartupEventArgs e) + void HandleStartup() { IsStarted = true; IsActive = Win32.ApplicationIsActivated();