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] Fix for MenuFlyoutItems programmatically added to MenuFlyoutSubItems are not visible #26886

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
81 changes: 81 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26856.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 26856, "MenuFlyoutItems programmatically added to MenuFlyoutSubItems are not visible", PlatformAffected.UWP)]
public class Issue26856 : TestShell
{
protected override void Init()
{
// Create MenuBarItem
var menuBarItem = new MenuBarItem { Text = "Menu Flyout Item" };

// Add MenuFlyoutItem to MenuBarItem
menuBarItem.Add(new MenuFlyoutItem { Text = "Original Item" });

// Create MenuFlyoutSubItem
var menuFlyoutSubItem = new MenuFlyoutSubItem { Text = "Flyout" };

// Add MenuFlyoutItem to MenuFlyoutSubItem
menuFlyoutSubItem.Add(new MenuFlyoutItem { Text = "Original Sub Item" });

// Add MenuFlyoutSubItem to MenuBarItem
menuBarItem.Add(menuFlyoutSubItem);

// Add MenuBarItem to MenuBarItems
MenuBarItems.Add(menuBarItem);

var layout = new VerticalStackLayout
{
Padding = new Thickness(30, 0),
Spacing = 25
};

var label = new Label { Text = "Menu Test" };
var button = new Button
{
Text = "Add Flyout Sub Item"
};
button.AutomationId = "Button";

button.Clicked += OnButtonClicked;

// Add elements to layout
layout.Children.Add(label);
layout.Children.Add(button);

// Set Content of the Page
AddContentPage(new ContentPage { Content = layout });
FlyoutBehavior = FlyoutBehavior.Disabled;
}

private void OnButtonClicked(object sender, EventArgs e)
{
MenuFlyoutSubItem menuFlyoutSubItem = GetSubMenu("Flyout");

MenuFlyoutItem itemToAdd = new()
{
Text = "Added Sub Item",
IsEnabled = true,
Parent = menuFlyoutSubItem
};
menuFlyoutSubItem.Add(itemToAdd);

}

public MenuFlyoutSubItem GetSubMenu(string name)
{
MenuFlyoutSubItem result = null;

MenuBarItems.ToList().ForEach(menuBarItem =>
{
var foundItem = menuBarItem.SingleOrDefault(menuElement => menuElement is MenuFlyoutSubItem subMenu && subMenu.Text == name);

if (foundItem != null)
{
result = foundItem as MenuFlyoutSubItem;
}
});

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if WINDOWS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue26856 : _IssuesUITest
{
public override string Issue => "MenuFlyoutItems programmatically added to MenuFlyoutSubItems are not visible";

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

[Test]
[Category(UITestCategories.Page)]
public void MenuFlyoutItemShouldVisibleInsideMenuFlyoutSubItems()
{
App.WaitForElement("Button");
App.Tap("Button");
App.Tap("Menu Flyout Item");
App.WaitForElement("Flyout");
App.Tap("Flyout");
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 @@ -89,6 +89,10 @@ void Reset()
{
items = mfsi.Items;
}
else if (pvh.PlatformView is MenuBarItem menuBarItem)
{
items = menuBarItem.Items;
}

if (items is not null)
{
Expand Down
Loading