[Windows] "TitleBar.ExtendsContentIntoTitleBar = false" is now crashing startup every time in minimal Maui Project (regression, previously working)
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
I have been using `TitleBar.ExtendsContentIntoTitleBar = false` in windows for years now to set the TitleBar to a normal flat traditional view. However, today after updating my Visual Studio it is now crashing startup every time.
This can be reproduced by making a brand new blank Maui project and just changing App.xaml.cs to:
```
#if WINDOWS
using Microsoft.Maui.Handlers;
using Microsoft.UI.Windowing;
using Microsoft.UI;
using WinRT.Interop;
#endif
namespace TitleBarCrash
{
public partial class App : Application {
public App() {
InitializeComponent();
}
protected override Window CreateWindow(IActivationState? activationState) {
var window = new Window(new AppShell());
#if WINDOWS
window.HandlerChanged += (_, _) => {
SetExtendsContentIntoTitleBarFalse(window);
};
#endif
return window;
}
#if WINDOWS
//------------------------------
// SET TITLE BAR EXTENDS FALSE
//------------------------------
static void SetExtendsContentIntoTitleBarFalse(Window mauiWindow) {
if (mauiWindow.Handler is not WindowHandler handler)
return;
var xamlWindow = handler.PlatformView;
if (xamlWindow == null)
return;
var hwnd = WindowNative.GetWindowHandle(xamlWindow);
var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
var appWindow = AppWindow.GetFromWindowId(windowId);
//---> THIS LINE NOW CAUSES A CRASH! (did not previously)
appWindow.TitleBar.ExtendsContentIntoTitleBar = false;
}
#endif
}
}
```
Every time now, on startup it will crash with:
```
Exception thrown: 'System.InvalidOperationException' in WinRT.Runtime.dll
Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
The group or resource is not in the correct state to perform the requested operation.
The group or resource is not in the correct state to perform the requested operation.
The program '[37336] TitleBarCrash.exe' has exited with code 4294967295 (0xffffffff).
```
Something has obviously broken though I don't know what. This function is necessary to restore a normal flat full width opaque Title Bar which I require. I have tried setting `ExtendsContentIntoTitleBar = false` during many different Maui or WinUI event hooks to see if I can find any safe point but they all crash now.
Any fix would be greatly appreciated.
### Steps to Reproduce
Run demo project, with code as above, and it should crash with the error shown. I am testing on Windows 11 Home.
### Link to public reproduction project repository
https://github.com/jonmdev/TitleBarCrash
### Version with bug
9.0.12 SR1.2
10
### Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
### Last version that worked well
Unknown/Other
### Affected platforms
Windows
### Affected platform versions
_No response_
### Did you find any workaround?
No solution found. This is seen with a default Maui project made in up to date Visual Studio as of today.
Contributor guide
Research direction
Start with the public TitleBarCrash reproduction project and the Windows-specific code in App.xaml.cs. Run the minimal MAUI project on Windows, confirm the crash at appWindow.TitleBar.ExtendsContentIntoTitleBar = false, and inspect the related startup and title-bar handling. Done means the setting no longer crashes startup and restores the requested normal title bar.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100