microsoft / microsoft/microsoft-ui-xaml

SetTitleBar crash under specific condition

Open
#11,352 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area-TitleBar area-Windowing bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

I found that under specific condition, we need to wait for the element to be loaded in order to be able to call `SetTitleBar` to it instead of simply call it in window constructor, [as this documentation shows](https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window.settitlebar?view=windows-app-sdk-2.0)

Otherwise it causes the app crash.

### Why is this important?

The crash is confusing. And the document should be updated.

### Steps to reproduce the bug

1. If I specify the `Height` of this `Rectangle`, then `SetTitleBar` have to come **after** its `Loaded` event.
```xaml




```

```csharp
Bar.Loaded += (_, _) => SetTitleBar(Bar);
```

The app crashes if you do this:
```csharp
public MainWindow()
{
InitializeComponent();
ExtendsContentIntoTitleBar = true;
SetTitleBar(Bar);
}
```

2. However, if I simply replace the `Rectangle` with a `Grid` and use the exact crashing code above, it works now.
```xml




```

### Actual behavior

_No response_

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

2.2.0

### Windows version

Windows 11 (24H2): Build 26100

### Additional context

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash using the provided XAML and the MainWindow constructor that calls SetTitleBar on the Rectangle, then compare it with the Loaded-event version and the Grid variant. Start at SetTitleBar, ExtendsContentIntoTitleBar, and the Rectangle's Loaded event; done means identifying the condition, preventing the crash, and updating the referenced documentation if appropriate.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.