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 crash setting MenuFlyoutSubItem IconImageSource #26021

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jsuarezruiz
Copy link
Contributor

Description of Change

Fix crash setting MenuFlyoutSubItem IconImageSource on Windows.

From #24688 the ImageSource is added as logical children of the menu item. However, the LogicalChildrenInternalBackingStore collection from MenuFlyoutSubItem does a casting to IMenuElement

LogicalChildrenInternalBackingStore = new CastingList<Element, IMenuElement>(_menus);

Trying to add the IconImageSource to the LogicalChildrenInternalBackingStore insert a null value because this casting

_list.Add(item as TFrom);
fails, cannot convert from Element to IMenuElement.

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

Issues Fixed

Fixes #25893

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jsuarezruiz jsuarezruiz marked this pull request as draft November 21, 2024 16:09
@PureWeen PureWeen assigned PureWeen and unassigned Foda Nov 22, 2024
@jsuarezruiz
Copy link
Contributor Author

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

Added both, xlml test and UITest.

@@ -16,7 +16,12 @@ public partial class MenuFlyoutSubItem : MenuFlyoutItem, IMenuFlyoutSubItem

public MenuFlyoutSubItem()
{
LogicalChildrenInternalBackingStore = new CastingList<Element, IMenuElement>(_menus);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the casting list is a wrapper and if you change the source is is also reflected.

Adding new items to a new list is not going to keep them synced.

Can we use the casting list still and just go to Element?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

Setting MenuFlyoutSubItem IconImageSource throws a NullReferenceException
4 participants