diff --git a/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs b/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs index 2c467853d4..7b3de3306b 100644 --- a/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs +++ b/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs @@ -68,7 +68,7 @@ namespace Avalonia.Controls.ApplicationLifetimes return DoShutdown(new ShutdownRequestedEventArgs(), true, false, exitCode); } - internal void SetupCore(string[] args) + internal void SubscribeGlobalEvents() { if (_compositeDisposable is not null) { @@ -76,7 +76,7 @@ namespace Avalonia.Controls.ApplicationLifetimes // Until developer started it manually later. To avoid API breaking changes, it will execute Setup method twice. return; } - + _compositeDisposable = new CompositeDisposable( Window.WindowOpenedEvent.AddClassHandler(typeof(Window), (sender, _) => { @@ -91,7 +91,12 @@ namespace Avalonia.Controls.ApplicationLifetimes var window = (Window)sender!; _windows.Remove(window); HandleWindowClosed(window); - })); + })); + } + + internal void SetupCore(string[] args) + { + SubscribeGlobalEvents(); Startup?.Invoke(this, new ControlledApplicationLifetimeStartupEventArgs(args)); @@ -214,6 +219,7 @@ namespace Avalonia { var lifetime = builder.LifetimeOverride?.Invoke(typeof(ClassicDesktopStyleApplicationLifetime)) as ClassicDesktopStyleApplicationLifetime ?? new ClassicDesktopStyleApplicationLifetime(); + lifetime.SubscribeGlobalEvents(); lifetime.Args = args; lifetimeBuilder?.Invoke(lifetime);