dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.27k stars 1.76k forks source link

[Windows] Fix crash setting MenuFlyoutSubItem IconImageSource #26021

Open jsuarezruiz opened 3 days ago

jsuarezruiz commented 3 days ago

Description of Change

Fix crash setting MenuFlyoutSubItem IconImageSource on Windows.

From https://github.com/dotnet/maui/pull/24688 the ImageSource is added as logical children of the menu item. However, the LogicalChildrenInternalBackingStore collection from MenuFlyoutSubItem does a casting to IMenuElement https://github.com/dotnet/maui/blob/5b5aaa5ef83f54688bee408cf14768f443d5aa2e/src/Controls/src/Core/Menu/MenuFlyoutSubItem.cs#L19

Trying to add the IconImageSource to the LogicalChildrenInternalBackingStore insert a null value because this casting https://github.com/dotnet/maui/blob/5b5aaa5ef83f54688bee408cf14768f443d5aa2e/src/Controls/src/Core/ReadOnlyCastingList.cs#L91 fails, cannot convert from Element to IMenuElement.

This PR apply changes to allow Element in the LogicalChildrenInternalBackingStore collection from MenuFlyoutSubItem.

Issues Fixed

Fixes #25893

jsuarezruiz commented 2 days ago

Can you use a unit test here instead of a UI test?

Added both, xlml test and UITest.