microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
Frame.Navigate throws when clicking unselected item in GridView
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
- Create a page, with GridView inside it
- In GridView items, put a button that triggers navigation to another page
- When clicking the button without selecting the item first, Frame.Navigate throws
- 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.
I experience the same issue. Did you find any workaround for this (apart from changing to 1.0.0-preview3)?
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();
}
Thank you for the workaround. Hopefully you can fix it soon.
@JJBrychell FYI
The issue is not fixed in 1.0.1 or 1.1.0-preview.
I have also the same problem in version 1.1.3.
@ranjeshj can the controls team look at a global fix for this, instead of the workaround?
This can be repro'd on WinUI 2.
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.
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.
The bug is still present in WinAppSDK 1.3 and latest preview 1.4.230628000-preview1. Please reopen this.
@evelynwu-msft could we add a maui label to this?
@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.
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(); }
@llongley can you provide which version will include this fix? Thanks!
@huoyaoyuan The fix will be in WinAppSDK 1.5. It did not make it into the 1.5-experimental2 release today.