microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Frame.Navigate throws when clicking unselected item in GridView

Open huoyaoyuan opened this issue 2 years ago • 8 comments

Describe the bug

If a frame navigation is triggered by clicking a button in unselected item in GridView, it will throw with 'Child collection must not be modified during measure or arrange'.

This is a regression from 1.0.0-preview3

Steps to reproduce the bug

  1. Create a page, with GridView inside it
  2. In GridView items, put a button that triggers navigation to another page
  3. When clicking the button without selecting the item first, Frame.Navigate throws
  4. If select the item first then click the button inside it, it will not throw

Expected behavior

Navigate successfully without exception.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.0.0

Windows app type

  • [ ] UWP
  • [X] Win32

Device form factor

Desktop

Windows version

May 2021 Update (19043)

Additional context

Minimal repro: GridViewNavigationRepro.zip

Changing WindowsAppSDK to 1.0.0-preview3 and the problem disappears.

huoyaoyuan avatar Nov 19 '21 06:11 huoyaoyuan

I experience the same issue. Did you find any workaround for this (apart from changing to 1.0.0-preview3)?

dynsim avatar Dec 06 '21 07:12 dynsim

Thanks for the repro. We've done some debugging and the issue is that the button on the page that's being navigating away from has captured the pointer (normal for pointer press on a button), then that capture is being canceled as part of navigating away, which is triggering an attempt to modify a tree that's in the process of being torn down.

As a workaround for now you can release the button's capture:

private void Button_Click(object sender, RoutedEventArgs e)
{
    (sender as Button).ReleasePointerCaptures();
    Messenger.Navigate();
}

MikeHillberg avatar Dec 06 '21 23:12 MikeHillberg

Thank you for the workaround. Hopefully you can fix it soon.

huoyaoyuan avatar Dec 08 '21 09:12 huoyaoyuan

@JJBrychell FYI

StephenLPeters avatar Feb 16 '22 21:02 StephenLPeters

The issue is not fixed in 1.0.1 or 1.1.0-preview.

huoyaoyuan avatar Apr 07 '22 08:04 huoyaoyuan

I have also the same problem in version 1.1.3.

SteezCram avatar Aug 07 '22 13:08 SteezCram

@ranjeshj can the controls team look at a global fix for this, instead of the workaround?

Scottj1s avatar Aug 29 '22 18:08 Scottj1s

This can be repro'd on WinUI 2.

SamChaps avatar Sep 21 '22 22:09 SamChaps

Do you have a date for a fix? It is not possible to require users to first select a grid item before clicking on it.

Also, as I use a template for my grid, I haven't found a way to apply the workaround with the button clickl.

mickaelfrancois avatar Jan 23 '23 19:01 mickaelfrancois

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 29 '23 16:07 github-actions[bot]

The bug is still present in WinAppSDK 1.3 and latest preview 1.4.230628000-preview1. Please reopen this.

huoyaoyuan avatar Aug 04 '23 04:08 huoyaoyuan

@evelynwu-msft could we add a maui label to this?

mattleibow avatar Oct 17 '23 22:10 mattleibow

@evelynwu-msft could we add a maui label to this?

I am facing this issue with WinUI3 App also.

Edit:

The problem I was facing was due to not setting Page.NavigationCacheMode. The default value of which is Disabled.

Once I set it to Enabled, it worked as expected. Setting it to Disabled repeatedly caused the said exception.

Gueztt avatar Nov 26 '23 12:11 Gueztt

I can confirm I'm receiving the same error in a UWP application, WinUI v2.8.5.

Having a command bound to my Button while the click event was doing this seemed to work for now (didn't need Messenger.Navigate() there though in my case, the command handles navigation):

private void Button_Click(object sender, RoutedEventArgs e)
{
    (sender as Button).ReleasePointerCaptures();
    Messenger.Navigate();
}

hjohnson12 avatar Dec 05 '23 23:12 hjohnson12

@llongley can you provide which version will include this fix? Thanks!

huoyaoyuan avatar Jan 25 '24 08:01 huoyaoyuan

@huoyaoyuan The fix will be in WinAppSDK 1.5. It did not make it into the 1.5-experimental2 release today.

codendone avatar Jan 26 '24 06:01 codendone