microsoft / microsoft/microsoft-ui-xaml

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

Open
#10,836 0 comments 0 reactions 0 assignees View on GitHub
bug needs-triage
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### 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
```cs
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
}
```
2. 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_

Contributor guide

Open the contributing guide

Research direction

Start with the provided AppWindow.Closing and Application.Current.Exit() reproduction on Windows App SDK 1.8.2. Trace the exit path and compare it with normal window closing, then verify that AppWindow.Closing is raised and remains cancellable before AppWindow.Destroying; no source file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.