Skip to content

Commit

Permalink
[Windows][ Add correct menu bar item foreground resource override (#2…
Browse files Browse the repository at this point in the history
…6413)

* Add correct menu bar item foreground resource override

* Fix screenshot validation

* Add ref image

---------

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
  • Loading branch information
Foda and Mike Corsaro authored Dec 6, 2024
1 parent e72f6ad commit 7bfe434
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.None, 0, "Shell MenuBarItems Test",
PlatformAffected.WinRT)]
public class ShellMenuBarItems : TestShell
{
protected override void Init()
{
var menuBarItem = new MenuBarItem()
{
Text = "Title 1"
};

var menuBarItem2 = new MenuBarItem()
{
Text = "Title 2"
};

menuBarItem.Add(new MenuFlyoutItem()
{
Text = "Item 1"
});
menuBarItem.Add(new MenuFlyoutItem()
{
Text = "Item 2"
});
menuBarItem.Add(new MenuFlyoutItem()
{
Text = "Item 3"
});

var contentPage = new ContentPage()
{
Content = new Label() { Text = "Shell MenuBarItems Test" }
};

contentPage.MenuBarItems.Add(menuBarItem);
contentPage.MenuBarItems.Add(menuBarItem2);

AddContentPage(contentPage);

FlyoutBehavior = FlyoutBehavior.Disabled;

// Set menu bar and menu bar item foreground color
SetBackgroundColor(this, Colors.Purple);
SetTitleColor(this, Colors.White);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
#if WINDOWS
public class ShellMenuIBarItemsTest : _IssuesUITest
{
public ShellMenuIBarItemsTest(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Shell MenuBarItems Test";

[Test]
[Category(UITestCategories.Shell)]
public void SettingMenuBarItemColorsWork()
{
Task.Delay(millisecondsDelay: 100).Wait();

VerifyScreenshot("VerifyMenuBarItemColorsWork");
}
}
#endif
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions src/Core/src/Platform/Windows/MauiToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,18 @@ void UpdateMenuBarForeground()
if (_menuBar is null)
return;

// MenuBarItems currently don't respect the Foreground property due to https://github.com/microsoft/microsoft-ui-xaml/issues/7070
// Work around this by setting the Button's colors in the MenuBar's ResourceDictionary

ResourceDictionary dictionary = _menuBar.Resources;
WBrush? menuForegroundBrush = _menuBarForeground;
if (menuForegroundBrush is null)
{
dictionary.Remove("ButtonForeground");
dictionary.Remove("MenuBarItemForeground");
dictionary.Remove("ButtonForegroundPointerOver");
dictionary.Remove("ButtonForegroundPressed");
dictionary.Remove("ButtonForegroundDisabled");
}
else
{
dictionary["ButtonForeground"] = menuForegroundBrush;
dictionary["MenuBarItemForeground"] = menuForegroundBrush;
dictionary["ButtonForegroundPointerOver"] = menuForegroundBrush;
dictionary["ButtonForegroundPressed"] = menuForegroundBrush;
dictionary["ButtonForegroundDisabled"] = menuForegroundBrush;
Expand Down

0 comments on commit 7bfe434

Please sign in to comment.