Skip to content

Commit

Permalink
Fix titlebar not being added to modal "windows" (#26794)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 25, 2024
1 parent 5cd3863 commit e3908a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
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

0 comments on commit e3908a6

Please sign in to comment.