diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs index bc7081c60994..800d6d1af9de 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs @@ -6,6 +6,7 @@ using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers; using Microsoft.Maui.Controls.Platform; +using Microsoft.Maui.Graphics; using Microsoft.Maui.Platform; using Microsoft.UI.Xaml; using Xunit; @@ -23,6 +24,53 @@ protected Task CheckFlyoutState(ShellHandler handler, bool desiredState) return Task.CompletedTask; } + [Theory(DisplayName = "Shell FlyoutBackground Initializes Correctly")] + [InlineData("#FF0000")] + [InlineData("#00FF00")] + [InlineData("#0000FF")] + [InlineData("#000000")] + public async Task ShellFlyoutBackgroundInitializesCorrectly(string colorHex) + { + SetupBuilder(); + + var expectedColor = Color.FromArgb(colorHex); + + var shell = await CreateShellAsync((shell) => + { + shell.FlyoutBehavior = FlyoutBehavior.Locked; + shell.FlyoutBackground = new SolidColorBrush(expectedColor); + + var shellItem = new FlyoutItem(); + shellItem.Items.Add(new ContentPage()); + shell.Items.Add(shellItem); + }); + + await InvokeOnMainThreadAsync(async () => + { + await CreateHandlerAndAddToWindow(shell, (handler) => + { + var rootNavView = handler.PlatformView; + var shellItemView = shell.CurrentItem.Handler.PlatformView as MauiNavigationView; + var expectedRoot = UI.Xaml.Controls.NavigationViewPaneDisplayMode.Left; + var expectedShellItems = UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal; + + Assert.Equal(expectedRoot, rootNavView.PaneDisplayMode); + Assert.NotNull(shellItemView); + Assert.Equal(expectedShellItems, shellItemView.PaneDisplayMode); + + return Task.CompletedTask; + }); + + await AssertionExtensions.Wait(() => + { + var platformView = shell.Handler.PlatformView as FrameworkElement; + return platformView is not null && (platformView.Height > 0 || platformView.Width > 0); + }); + }); + + await ValidateHasColor(shell, expectedColor, typeof(ShellHandler)); + } + [Fact(DisplayName = "Back Button Enabled/Disabled")] public async Task BackButtonEnabledAndDisabled() { @@ -631,4 +679,4 @@ async Task TapToSelect(ContentPage page) await OnNavigatedToAsync(page); } } -} \ No newline at end of file +} diff --git a/src/Core/src/Platform/Windows/NavigationViewExtensions.cs b/src/Core/src/Platform/Windows/NavigationViewExtensions.cs index f45f3f3f42e7..4645f8226749 100644 --- a/src/Core/src/Platform/Windows/NavigationViewExtensions.cs +++ b/src/Core/src/Platform/Windows/NavigationViewExtensions.cs @@ -42,6 +42,8 @@ public static void UpdateTopNavigationViewItemTextColor(this MauiNavigationView navigationView.TopNavArea.Resources["TopNavigationViewItemForegroundPressed"] = brush; navigationView.TopNavArea.Resources["TopNavigationViewItemForegroundDisabled"] = brush; } + + navigationView.TopNavArea.RefreshThemeResources(); } if (navigationView.MenuItemsSource is IList items) @@ -70,6 +72,8 @@ public static void UpdateTopNavigationViewItemBackgroundUnselectedColor(this Mau navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundPointerOver"] = brush; navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundPressed"] = brush; } + + navigationView.TopNavArea.RefreshThemeResources(); } if (navigationView.MenuItemsSource is IList items) @@ -98,6 +102,8 @@ public static void UpdateTopNavigationViewItemBackgroundSelectedColor(this MauiN navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundSelectedPointerOver"] = brush; navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundSelectedPressed"] = brush; } + + navigationView.TopNavArea.RefreshThemeResources(); } if (navigationView.MenuItemsSource is IList items) @@ -111,32 +117,28 @@ public static void UpdateTopNavigationViewItemBackgroundSelectedColor(this MauiN public static void UpdatePaneBackground(this MauiNavigationView navigationView, Paint? paint) { - var rootSplitView = navigationView.RootSplitView; + var paneContentGrid = navigationView.PaneContentGrid; + + if (paneContentGrid is null) + return; + var brush = paint?.ToPlatform(); - if (brush == null) + if (brush is null) { - object? color = null; + object? color; if (navigationView.IsPaneOpen) color = navigationView.Resources["NavigationViewExpandedPaneBackground"]; else color = navigationView.Resources["NavigationViewDefaultPaneBackground"]; - if (rootSplitView != null) - { - if (color is WBrush colorBrush) - rootSplitView.PaneBackground = colorBrush; - else if (color is global::Windows.UI.Color uiColor) - rootSplitView.PaneBackground = new WSolidColorBrush(uiColor); - } + if (color is WBrush colorBrush) + paneContentGrid.Background = colorBrush; + else if (color is global::Windows.UI.Color uiColor) + paneContentGrid.Background = new WSolidColorBrush(uiColor); } else - { - if (rootSplitView != null) - { - rootSplitView.PaneBackground = brush; - } - } + paneContentGrid.Background = brush; } public static void UpdateFlyoutVerticalScrollMode(this MauiNavigationView navigationView, ScrollMode scrollMode)