[WinUI] Fix exception when adding items to a linear layout CollectionView #16958
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
When having a
CollectionView
with a Linear horizontal layout in aGrid
with a row definition set to Auto, adding an item would make rezising the innerItemsWrapGrid
enter in an inifinite loop making the height grow indefinetly. The same would happen for for vertical/column/width.The problem was that when using a linear layout the wrap grid should never have more than one row (it shouldn't wrap the items after exceding its size), regardless of the space available, but the wrap grid was not aware of this. The cycle happened when the wrap grid total height (or width, depending on the orientation) increased, so then we update the item height, but as span is 1 because of linear layout, we ended up setting the total height as item height, forcing the wrap grid to grow again.
The fix is simply configure the
ItemsWrapGrid
to restrict the number of rows/columns it can have based on what's set for Span.Issues Fixed
Fixes #16320
Sample provided in the issue after this fix: