-
Notifications
You must be signed in to change notification settings - Fork 712
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
Fix issue with collection change inside item invoked crashing NavigationView #3138
Fix issue with collection change inside item invoked crashing NavigationView #3138
Conversation
|
||
<muxcontrols:NavigationView | ||
Width="400" PaneDisplayMode="Left" | ||
MenuItemsSource="{x:Bind Pages, Mode=OneWay}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[](start = 0, length = 2)
nit: tabs should be spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly manipulating the `NavigationView::MenuItems` vector is bad. If you do that, you're gonna get crashes, in WinUI code for `Measure`. However, a WinUI PR (below) gave me an idea: Changing `NavigationView::MenuItemsSource` will wholly invalidate the entirety of the nav view items, and that will avoid the crash. This code does that. It's a wee bit janky, but it works. Closes #13673 _might_ affect #12333, need to try and repro. See also: * #9273 * #10390 * microsoft/microsoft-ui-xaml#6302 * microsoft/microsoft-ui-xaml#3138, which was the fix for microsoft/microsoft-ui-xaml#2818
Directly manipulating the `NavigationView::MenuItems` vector is bad. If you do that, you're gonna get crashes, in WinUI code for `Measure`. However, a WinUI PR (below) gave me an idea: Changing `NavigationView::MenuItemsSource` will wholly invalidate the entirety of the nav view items, and that will avoid the crash. This code does that. It's a wee bit janky, but it works. Closes #13673 _might_ affect #12333, need to try and repro. See also: * #9273 * #10390 * microsoft/microsoft-ui-xaml#6302 * microsoft/microsoft-ui-xaml#3138, which was the fix for microsoft/microsoft-ui-xaml#2818 (cherry picked from commit 8c17475) Service-Card-Id: 88428128 Service-Version: 1.17
Description
When changing the MenuItemsSource of a NavigationView inside the ItemInvoked handler, new items might not be realized resulting in invalid indices. NavView however assumed that at that state all items are realized which is a problem if the MenuItemsSource changed while processing the ItemInvoked event.
Motivation and Context
Fixes #2818
How Has This Been Tested?
Add new interaction test.
Screenshots (if appropriate):