Skip to content
Open
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
52 changes: 52 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16119.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 16119, "MenuFlyoutItem with FileImageSource displays icon in monochrome instead of original colors", PlatformAffected.UWP)]
public class Issue16119 : TestShell
{
protected override void Init()
{
MenuBarItem menuBarItem = new MenuBarItem { Text = "Menu Flyout Item" };

MenuFlyoutItem menuFlyoutItem = new MenuFlyoutItem
{
Text = "Hello World",
IconImageSource = new FileImageSource { File = "small_dotnet_bot.png" }
};
menuBarItem.Add(menuFlyoutItem);

MenuFlyoutSubItem menuFlyoutSubItem = new MenuFlyoutSubItem
{
Text = "Sub Menu",
IconImageSource = new FileImageSource { File = "small_dotnet_bot.png" }
};

menuFlyoutSubItem.Add(new MenuFlyoutItem
{
Text = "Sub Item 1",
IconImageSource = new FileImageSource { File = "small_dotnet_bot.png" }
});

menuBarItem.Add(menuFlyoutSubItem);
MenuBarItems.Add(menuBarItem);

VerticalStackLayout layout = new VerticalStackLayout
{
Padding = new Thickness(30, 0),
Spacing = 25,
VerticalOptions = LayoutOptions.Center,
Children =
{
new Label
{
AutomationId = "Issue16119DescriptionLabel",
Text = "The test passes if the MenuFlyoutItem and MenuFlyoutSubItem icons are in original color instead of monochrome",
HorizontalOptions = LayoutOptions.Center,
FontSize = 12
},
}
};

AddContentPage(new ContentPage { Content = layout });
FlyoutBehavior = FlyoutBehavior.Disabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if WINDOWS //Menu bar items only for desktop apps. For more information : https://learn.microsoft.com/en-us/dotnet/maui/user-interface/menu-bar?view=net-maui-9.0
//On MacCatalyst, menu items are part of the native macOS menu bar (e.g., Apple, File, Edit) at the top of the screen. So this is not implemented for Mac
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue16119 : _IssuesUITest
{
public override string Issue => "MenuFlyoutItem with FileImageSource displays icon in monochrome instead of original colors";

public Issue16119(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Page)]
public void VerifyMenuFlyoutIconDisplaysOriginalColor()
{
App.WaitForElement("Issue16119DescriptionLabel");
App.Tap("Menu Flyout Item");

VerifyScreenshot();
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ void OnClicked(object sender, UI.Xaml.RoutedEventArgs e)

public static void MapSource(IMenuFlyoutItemHandler handler, IMenuFlyoutItem view)
{
handler.PlatformView.Icon =
view.Source?.ToIconSource(handler.MauiContext!)?.CreateIconElement();
var iconSource = view.Source?.ToIconSource(handler.MauiContext!);

// Ensure MenuFlyoutItem icons preserve original colors instead of showing as monochrome silhouettes
if (iconSource is BitmapIconSource bitmapIconSource)
{
bitmapIconSource.ShowAsMonochrome = false;
}

handler.PlatformView.Icon = iconSource?.CreateIconElement();
}

public static void MapText(IMenuFlyoutItemHandler handler, IMenuFlyoutItem view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public static void MapIsEnabled(IMenuFlyoutSubItemHandler handler, IMenuFlyoutSu

public static void MapSource(IMenuFlyoutSubItemHandler handler, IMenuFlyoutSubItem view)
{
handler.PlatformView.Icon =
view.Source?.ToIconSource(handler.MauiContext!)?.CreateIconElement();
var iconSource = view.Source?.ToIconSource(handler.MauiContext!);

if (iconSource is BitmapIconSource bitmapIconSource)
{
bitmapIconSource.ShowAsMonochrome = false;
}

handler.PlatformView.Icon = iconSource?.CreateIconElement();
}

public override void SetVirtualView(IElement view)
Expand Down
Loading