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

[regression/8.0.0-preview.6.8686] [WinUI] CollectionView throws an exception after adding a second item #16320

Closed
marchev-prgs opened this issue Jul 24, 2023 · 2 comments · Fixed by #16958
Assignees
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 i/regression This issue described a confirmed regression on a currently supported version layout-grid partner Issue or Request from a partner team platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@marchev-prgs
Copy link

Description

(repro project is in link)

I have a CollectionView in a Grid with row definition auto.

<Grid>
    <Grid RowDefinitions="Auto, *">
        <CollectionView x:Name="cv1" BackgroundColor="LightSalmon">
            <CollectionView.ItemsLayout>
                <LinearItemsLayout Orientation="Horizontal" />
            </CollectionView.ItemsLayout>
        </CollectionView>
        <Label Text="A Label under the CollectionView" Grid.Row="1" />
    </Grid>
    <Button Text="add" Clicked="ButtonAdd_Clicked" HorizontalOptions="End" VerticalOptions="Start" />
</Grid>

The CollectionView is initially displayed properly, but after I add a second item into it, via click of a button - an exception is thrown:

message:
Exception = {"Value does not fall within the expected range."}

stack trace:
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.IFrameworkElementOverridesMethods.ArrangeOverride(IObjectReference _obj, Size finalSize)
at Microsoft.UI.Xaml.FrameworkElement.ArrangeOverride(Size finalSize)
at Microsoft.Maui.Controls.Platform.FormsGridView.ArrangeOverride(Size finalSize)
at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.ArrangeOverride(Size finalSize)
at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_ArrangeOverride_1(IntPtr thisPtr, Size finalSize, Size* result)
--- End of stack trace from previous location ---
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.IUIElementMethods.Arrange(IObjectReference _obj, Rect finalRect)
at Microsoft.UI.Xaml.UIElement.Arrange(Rect finalRect)
at Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler(IViewHandler viewHandler, Rect rect)
at Microsoft.Maui.Handlers.ViewHandler`2.PlatformArrange(Rect rect)
at Microsoft.Maui.Controls.VisualElement.ArrangeOverride(Rect bounds)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange(Rect bounds)
at Microsoft.Maui.Layouts.GridLayoutManager.ArrangeChildren(Rect bounds)
at Microsoft.Maui.Controls.Layout.CrossPlatformArrange(Rect bounds)
at Microsoft.Maui.Platform.MauiPanel.CrossPlatformArrange(Rect bounds)
at Microsoft.Maui.Platform.MauiPanel.ArrangeOverride(Size finalSize)
at Microsoft.Maui.Platform.LayoutPanel.ArrangeOverride(Size finalSize)
at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.ArrangeOverride(Size finalSize)
at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_ArrangeOverride_1(IntPtr thisPtr, Size finalSize, Size* result)

cv_exc_1

Interestingly we tested this on two different machies with the same maui versions and one of the does not throw an exception, but results in an invalid layout:
cv_exc_2

I placed this code inside the button click handler:
double collectionViewHeight = this.cv1.DesiredSize.Height;
And I can see that the size of the CollectionView is very very large:
collectionViewHeight = 954437184

Steps to Reproduce

  1. Get the repo from the provided link
  2. Run the app in WinUI
  3. Click the Add button in the upper right corner

Expected: Two items should be displayed in the CollectionView.
Actual: An exception is thrown.

Link to public reproduction project repository

https://github.com/telerik/ms-samples/tree/main/Maui/CollectionViewThrowsAnException

Version with bug

Unknown/Other

Last version that worked well

7.0.86

Affected platforms

Windows

Affected platform versions

8.0.0-preview.6.8686

Did you find any workaround?

N/A

Relevant log output

No response

@marchev-prgs marchev-prgs added the t/bug Something isn't working label Jul 24, 2023
@PureWeen PureWeen added partner Issue or Request from a partner team i/regression This issue described a confirmed regression on a currently supported version area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/windows 🪟 labels Jul 24, 2023
@PureWeen PureWeen added this to the .NET 8 GA milestone Jul 24, 2023
@jsuarezruiz
Copy link
Contributor

image

@samhouts samhouts changed the title [WinUI] CollectionView throws an exception after adding a second item [regression/8.0.0-preview.6.8686] [WinUI] CollectionView throws an exception after adding a second item Aug 1, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Aug 10, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on Windows 11(8.0.100-preview.6.23330.14), not repro on Android 13.0-API33 and iOS 16.4 with below Project:
CollectionViewThrowsAnException.zip

@emaf emaf self-assigned this Aug 11, 2023
emaf added a commit that referenced this issue Aug 16, 2023
emaf added a commit that referenced this issue Aug 23, 2023
…View

When having a `CollectionView` with a Linear horizontal layout in a `Grid` with a row definition set to Auto, adding an item would make rezising the inner `ItemsWrapGrid` 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.

Fixes #16320
@github-project-automation github-project-automation bot moved this from Todo to Done in MAUI SDK Ongoing Aug 24, 2023
rmarinho pushed a commit that referenced this issue Aug 24, 2023
…View (#16958)

When having a `CollectionView` with a Linear horizontal layout in a `Grid` with a row definition set to Auto, adding an item would make rezising the inner `ItemsWrapGrid` 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.

Fixes #16320
@ghost ghost locked as resolved and limited conversation to collaborators Sep 23, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 i/regression This issue described a confirmed regression on a currently supported version layout-grid partner Issue or Request from a partner team platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants