diff --git a/src/Controls/src/Core/Menu/MenuFlyoutSubItem.cs b/src/Controls/src/Core/Menu/MenuFlyoutSubItem.cs index 3f606a85523c..8c0686fb2a4d 100644 --- a/src/Controls/src/Core/Menu/MenuFlyoutSubItem.cs +++ b/src/Controls/src/Core/Menu/MenuFlyoutSubItem.cs @@ -1,29 +1,24 @@ #nullable disable -using System; using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Windows.Input; -using Microsoft.Maui.Controls.StyleSheets; -using Microsoft.Maui.Graphics; +using System.Linq; namespace Microsoft.Maui.Controls { public partial class MenuFlyoutSubItem : MenuFlyoutItem, IMenuFlyoutSubItem { - readonly List _menus = new List(); + readonly List _menus = new List(); public MenuFlyoutSubItem() { - LogicalChildrenInternalBackingStore = new CastingList(_menus); + LogicalChildrenInternalBackingStore = new CastingList(_menus); } private protected override IList LogicalChildrenInternalBackingStore { get; } public IMenuElement this[int index] { - get { return _menus[index]; } + get { return _menus[index] as IMenuElement; } set { RemoveAt(index); @@ -60,7 +55,7 @@ public void CopyTo(IMenuElement[] array, int arrayIndex) public IEnumerator GetEnumerator() { - return _menus.GetEnumerator(); + return _menus.Cast().GetEnumerator(); } public int IndexOf(IMenuElement item) @@ -87,7 +82,7 @@ public void RemoveAt(int index) { var item = _menus[index]; RemoveLogicalChild((Element)item, index); - NotifyHandler(nameof(IMenuFlyoutHandler.Remove), index, item); + NotifyHandler(nameof(IMenuFlyoutHandler.Remove), index, item as IMenuElement); } IEnumerator IEnumerable.GetEnumerator() diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue25893.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue25893.xaml new file mode 100644 index 000000000000..911a6385548e --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue25893.xaml @@ -0,0 +1,23 @@ + + + +