diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs index 57f07379b8d9..40f2a7b25d87 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs @@ -422,5 +422,47 @@ public async Task When_MenuFlyout_DataContext_Changes_In_Opening() } } } + +#if HAS_UNO + [TestMethod] + public async Task When_Toggle_Item_HasToggle() + { + var toggleItem = new ToggleMenuFlyoutItem(); + Assert.IsTrue(toggleItem.HasToggle()); + } + + [TestMethod] + public async Task When_Menu_Contains_Toggle() + { + var menu = new MenuFlyout(); + menu.Items.Add(new MenuFlyoutItem() { Text = "Text" }); + + var trigger = new Button(); + TestServices.WindowHelper.WindowContent = trigger; + await TestServices.WindowHelper.WaitForLoaded(trigger); + + await ValidateToggleAsync(false); + + var toggleItem = new ToggleMenuFlyoutItem() { Text = "Toggle!" }; + menu.Items.Add(toggleItem); + await ValidateToggleAsync(true); + + menu.Items.Remove(toggleItem); + await ValidateToggleAsync(false); + + async Task ValidateToggleAsync(bool expected) + { + menu.ShowAt(trigger); + await TestServices.WindowHelper.WaitForIdle(); + var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot); + var popup = popups[0]; + Assert.IsInstanceOfType(popup.Child, typeof(MenuFlyoutPresenter)); + var presenter = (MenuFlyoutPresenter)popup.Child; + Assert.AreEqual(expected, presenter.GetContainsToggleItems()); + popup.IsOpen = false; + await TestServices.WindowHelper.WaitForIdle(); + } + } +#endif } } diff --git a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs index 93afca5269b9..f2f082c15d89 100644 --- a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs +++ b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs @@ -168,5 +168,7 @@ private void OnIsCheckedChanged(bool oldValue, bool newValue) // Create ToggleMenuFlyoutItemAutomationPeer to represent the protected override AutomationPeer OnCreateAutomationPeer() => new ToggleMenuFlyoutItemAutomationPeer(this); + + internal override bool HasToggle() => true; } }