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

[Windows][ Add correct menu bar item foreground resource override #26413

Merged
merged 3 commits into from
Dec 6, 2024
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
@@ -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
Loading