Open Takym opened 3 months ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Verified this issue with Visual Studio 17.11.0 Preview 1.1 (8.0.40 & 8.0.21). Can repro on Windows platform with sample project.
Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar
is set to true as default in line 45 of MauiWinUIWindow.cs
: https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/Platform/Windows/MauiWinUIWindow.cs#L27-L59NavigationRootManager
and setting visibility when the class is constructed: https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/Platform/Windows/NavigationRootManager.cs#L15-L27NavigationRootManager
is instantiated in the MakeWindowScope
function: https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/MauiContextExtensions.cs#L47-L72MakeWindowScope
is called immediately after which MauiWinUIWindow
has been created: https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/Platform/Windows/ApplicationExtensions.cs#L11-L33NavigationRootManager.SetTitleBarVisibility(bool)
which is called by the NavigationRootManager
constructor calls WindowRootView.UpdateAppTitleBar(int, bool)
which contains core codes for configuring a title bar: https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/Platform/Windows/NavigationRootManager.cs#L29-L51 https://github.com/dotnet/maui/blob/b182ffef2c85a5681686732a81b0f572a86591cc/src/Core/src/Platform/Windows/WindowRootView.cs#L105-L127I am not sure adding a new API is a good solution to fix a bug but I suggest adding a new lifecycle event WindowsLifecycle.OnWindowCreating
raised after var winuiWindow = new MauiWinUIWindow();
and before var mauiContext = applicationContext!.MakeWindowScope(winuiWindow, out var windowScope);
. So, you can modify the Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar
property in this new event.
Alternatively, I suggest adding a new constructor public MauiWinUIWindow(bool extendsContentIntoTitleBar)
and a new service interface like the one below:
public interface IDefaultExtendsContentIntoTitleBarValueProvider
{
public bool ExtendsContentIntoTitleBar { get; }
}
// Utility Extension Methods for a Builder:
// - UseSystemTitleBar()
// - UseCustomTitleBar()
Yet another alternatively, I suggest making NavigationRootManager.SetTitleBarVisibility(bool)
or WindowRootView.UpdateAppTitleBar(int, bool)
public. So, you can refresh a tile bar state at any time like the below:
void ShowCustomTitleBar(Microsoft.UI.Xaml.Window window, NavigationRootManager navRootMgr)
{
window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
navRootMgr.SetTitleBarVisibility(true);
}
void HideCustomTitleBar(Microsoft.UI.Xaml.Window window, NavigationRootManager navRootMgr)
{
window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = false;
navRootMgr.SetTitleBarVisibility(false);
}
void ShowCustomTitleBar(Microsoft.UI.Xaml.Window window, WindowRootView wndRootView)
{
window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
wndRootView.UpdateAppTitleBar(32, true);
}
void HideCustomTitleBar(Microsoft.UI.Xaml.Window window, WindowRootView wndRootView)
{
window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = false;
wndRootView.UpdateAppTitleBar(0, false);
}
https://github.com/dotnet/maui/issues/22784#issuecomment-2344085236
I have tried #24266 (comment) however the title bar is still shown doubly. I tested with this commit on the reproduction project: Takym/DoublyTitleBarsInMaui@9145222.
(I am sorry for the late reply.)
P.S. Current OS Version: Microsoft Windows [Version 10.0.19045.4894]
Description
In the Windows platform, I observed the window tile bar was shown doubly when I set
Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar
as false. I tried to set this property to false because I wanted to use the native title bar to show a title bar icon with a .ico file. In the current version, it is necessary to switch to the native title bar showing an icon.Steps to Reproduce
Set
Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar
as false like the below code:Screenshot for Actual Behavior
Screenshot for Expected Behavior
Link to public reproduction project repository
https://github.com/Takym/DoublyTitleBarsInMaui/blob/master/DoublyTitleBarsInMaui/MauiProgram.cs#L31
Version with bug
8.0.21 SR4.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Microsoft Windows [Version 10.0.19045.4412]
Did you find any workaround?
I could hide the second title bar by overlapping it with the native container (
FrameworkElement
object). This code is to set the container margin to(0, -32, 0, 0)
and the Z index to zero.I added this code below of
window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = false;
line.Relevant log output
No response