Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0.1xx-sr2] [Windows] Fix titlebar not being added to modals #26794

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,21 @@ void SetCurrent(
}

var windowManager = modalContext.GetNavigationRootManager();
var platform = newPage.ToPlatform(modalContext);
_waitingForIncomingPage = platform.OnLoaded(() => completedCallback?.Invoke());
windowManager.Connect(platform);
Container.AddPage(windowManager.RootView);
if (windowManager is not null)
{
// Set the titlebar on the new navigation root
if (previousPage is not null &&
previousPage.GetParentWindow() is Window window &&
window.TitleBar is TitleBar titlebar)
{
windowManager.SetTitleBar(titlebar, modalContext);
}

var platform = newPage.ToPlatform(modalContext);
_waitingForIncomingPage = platform.OnLoaded(() => completedCallback?.Invoke());
windowManager.Connect(platform);
Container.AddPage(windowManager.RootView);
}
}
// popping modal
else
Expand All @@ -135,6 +146,14 @@ void SetCurrent(
wrv.SetTitleBarVisibility(UI.Xaml.Visibility.Visible);
}

// Restore the titlebar
if (previousPage is not null &&
previousPage.GetParentWindow() is Window window &&
window.TitleBar is TitleBar titlebar)
{
windowManager.SetTitleBar(titlebar, context);
}

var platform = newPage.ToPlatform();
_waitingForIncomingPage = platform.OnLoaded(() => completedCallback?.Invoke());
Container.AddPage(windowManager.RootView);
Expand Down
13 changes: 10 additions & 3 deletions src/Core/src/Platform/Windows/WindowRootView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ internal void SetTitleBar(ITitleBar? titlebar, IMauiContext? mauiContext)

if (_titleBar is null || mauiContext is null)
{
UpdateBackgroundColorForButtons();
return;
}

Expand Down Expand Up @@ -506,10 +507,16 @@ private void TitlebarPropChanged_PropertyChanged(object? sender, PropertyChanged

private void UpdateBackgroundColorForButtons()
{
if (NavigationViewControl?.ButtonHolderGrid is not null &&
_titleBar?.Background is SolidPaint bg)
if (NavigationViewControl?.ButtonHolderGrid is not null)
{
NavigationViewControl.ButtonHolderGrid.Background = new SolidColorBrush(bg.Color.ToWindowsColor());
if (_titleBar?.Background is SolidPaint bg)
{
NavigationViewControl.ButtonHolderGrid.Background = new SolidColorBrush(bg.Color.ToWindowsColor());
}
else
{
NavigationViewControl.ButtonHolderGrid.Background = new SolidColorBrush(UI.Colors.Transparent);
}
}
}

Expand Down