Skip to content

AppWindow.Closing event is not fired when calling Application.Current.Exit() #10836

@d2phap

Description

@d2phap

Describe the bug

As the title: AppWindow.Closing event is not raised when calling Application.Current.Exit()

Why is this important?

Since the event is not fired, it's impossible to track the window or cancel the window closing action with AppWindowClosingEventArgs

Steps to reproduce the bug

  1. Having this code
private void PART_WindowContent_Loaded(object sender, RoutedEventArgs e)
{
    AppWindow.Closing += AppWindow_Closing;
    AppWindow.Destroying += AppWindow_Destroying;
}

private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs e)
{
    // this event is not fired
}

private void AppWindow_Destroying(AppWindow sender, object e)
{
    // this event is fired
}
  1. Call Application.Current.Exit() to quit the app while the window is open

Actual behavior

AppWindow.Closing is not fired

Expected behavior

AppWindow.Closing must be fired

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.8.2: 1.8.251003001

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions