Skip to content

Fix for MenuFlyoutItem stops working after navigating away from and back to page #25170

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

Merged
merged 23 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
21da0c2
fix-21675-Updated the BindingContext of MenuBarItem after page naviga…
BagavathiPerumal Oct 10, 2024
aab1a4b
fix-21675- Added UI testcase.
BagavathiPerumal Oct 10, 2024
7d2da5b
fix-21675-Removed unwanted space.
BagavathiPerumal Oct 10, 2024
e762e8a
Merge branch 'main' of https://github.com/BagavathiPerumal/maui into …
BagavathiPerumal Oct 10, 2024
7904dd6
fix-21675-removed unwanted spacing.
BagavathiPerumal Oct 10, 2024
5a8bc16
fix-21675-Updated testcase.
BagavathiPerumal Oct 10, 2024
0818f26
fix-21675-Updated the BindingContext of MenuBarItem after page naviga…
BagavathiPerumal Oct 10, 2024
d8f4b2d
fix-21675- Added UI testcase.
BagavathiPerumal Oct 10, 2024
ecc6ea6
fix-21675-Removed unwanted space.
BagavathiPerumal Oct 10, 2024
13bb22f
fix-21675-removed unwanted spacing.
BagavathiPerumal Oct 10, 2024
6e0ffd1
fix-21675-Updated testcase.
BagavathiPerumal Oct 10, 2024
4c04284
fix-21675-Updated testcase script.
BagavathiPerumal Oct 11, 2024
9be1bdc
fix-21675-Updated testcase which only execute for the Windows and MacOS
BagavathiPerumal Oct 17, 2024
11661bb
Merge branch 'main' of https://github.com/BagavathiPerumal/maui into …
BagavathiPerumal Oct 17, 2024
8d995ff
fix-21675-Conflict resolved.
BagavathiPerumal Oct 17, 2024
895f17c
Merge branch 'main' of https://github.com/BagavathiPerumal/maui into …
BagavathiPerumal Oct 22, 2024
17f9d4d
Merge branch 'main' of https://github.com/BagavathiPerumal/maui into …
BagavathiPerumal Oct 25, 2024
13fe6cd
fix-21675-Moved testcase classes to Issue21675.
BagavathiPerumal Nov 7, 2024
8c52cfb
Update src/Controls/src/Core/Page/Page.cs
rmarinho Nov 16, 2024
f9dac1e
Merge branch 'dotnet:main' into fix-21675
BagavathiPerumal Nov 28, 2024
801b6ce
Merge branch 'main' of https://github.com/BagavathiPerumal/maui into …
BagavathiPerumal Jan 6, 2025
76bfa3d
fix-21675-Added UnitTestcase and removed UI testcase.
BagavathiPerumal Jan 30, 2025
af8c599
fix-21675- Parent of the MenuBarItems only null when the parent is Me…
BagavathiPerumal Feb 5, 2025
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
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Menu/MenuBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void RemoveAt(int index)
_menus.RemoveAt(index);
NotifyHandler(nameof(IMenuBarHandler.Remove), index, item);

if (item is Element e)
if (item is Element e && e.Parent == this)
e.Parent = null;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Controls/tests/Core.UnitTests/Menu/MenuTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ public void ClearUpdatesParent()
if (typeof(TChildType) == typeof(MenuBarItem))
{
(child0.Parent as ContentPage)!.MenuBarItems.Clear();

Assert.NotNull(child0.Parent);
Assert.NotNull(child1.Parent);
}
else
{
menuBar.Clear();
}

Assert.Null(child0.Parent);
Assert.Null(child1.Parent);
Assert.Null(child0.Parent);
Assert.Null(child1.Parent);
}
}

[Fact]
Expand Down
41 changes: 41 additions & 0 deletions src/Controls/tests/Core.UnitTests/MenuItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,46 @@ public void PartialHierarchyCanBeDisabled()
Assert.False(bottomLevelItem1.IsEnabled);
Assert.False(bottomLevelItem2.IsEnabled);
}

[Fact]
public async void UpdateMenuBarItemBindingContext()
{
bool fired = false;
var cmd = new Command(() => fired = true);
var bindingContext = new
{
MenuItemCommand = cmd
};

MenuFlyoutItem flyout;
MenuBarItem menuItem;
var mainPage = new ContentPage
{
MenuBarItems =
{
(menuItem = new MenuBarItem
{
(flyout = new MenuFlyoutItem { })
})
}
};

mainPage.BindingContext = bindingContext;
flyout.SetBinding(MenuFlyoutItem.CommandProperty, new Binding("MenuItemCommand"));

var page = new ContentPage
{
BindingContext = bindingContext
};

NavigationPage nav = new NavigationPage(mainPage);
TestWindow testWindow = new TestWindow(nav);
await mainPage.Navigation.PushAsync(page);
await page.Navigation.PopAsync();

flyout.Command.Execute(null);

Assert.True(fired);
}
}
}
Loading