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

Closed
wants to merge 10 commits into 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.

@jsuarezruiz jsuarezruiz requested a review from PureWeen November 22, 2024 09:57
@PureWeen PureWeen marked this pull request as ready for review November 25, 2024 15:25
@PureWeen PureWeen added the p/0 Work that we can't release without label Nov 25, 2024
@PureWeen PureWeen modified the milestones: .NET 9 SR1.1, .NET 9 SR2 Nov 25, 2024
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if this will work...

I feel like we've hit a point on this one where we actually need to maintain two different internal lists.

_menus no longer represents _menus it's a mix of types.

If someone calls RemoveAt(index) they are going to expect that it removes the menu specifically at the given index (we should also make sure this removes the ImageSource added)

So, I think we have to keep _menus as a list of IMenuElement to satisfy all the IList<IMenuElement> implementations.

And then the backing store for logical children basically has to be a mix of both.

We basically do this with Layout.cs, it has an internal list of _children it uses to satisfy the direct children but then it adds each of this to the logical children on the parent

@PureWeen PureWeen modified the milestones: .NET 9 SR2, .NET 9 SR3 Dec 6, 2024
@PureWeen
Copy link
Member

#26558

@PureWeen PureWeen closed this Dec 11, 2024
@PureWeen PureWeen removed this from the .NET 9 SR3 milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-flyout Flyout p/0 Work that we can't release without platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting MenuFlyoutSubItem IconImageSource throws a NullReferenceException
5 participants