dotnet / dotnet/maui

CollectionView does not update when changing ItemsLayout

Open
#7,747 3 comments 6 reactions 0 assignees View on GitHub
area-controls-collectionview platform/windows s/triaged t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I have a CollectionView with several items and I want to make a 2 column layout on wide screens and a 1 column layout on tall screens.

I tried setting a GridItemsLayout and changing the Span, but that did not work and then I tried changing the entire ItemsLayout, but still no updates in the app.

Restarting the app works, so this is just the result of changing at runtime.

### Steps to Reproduce

Add a CollectionView with items, and then say write this code to toggle the layout on page size changes:

```cs
private void OnSizeChanged(object? sender, EventArgs e) =>
collectionView.ItemsLayout = Width > 600
? new GridItemsLayout(2, ItemsLayoutOrientation.Vertical)
: new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
```

> NOTE: this should all be doable with AdaptiveTriggers, but that is not working currently #7242

### Version with bug

6.0 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Windows

### Affected platform versions

All

### Did you find any workaround?

_No response_

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the supplied OnSizeChanged reproduction and trace how CollectionView handles runtime assignments to ItemsLayout, including switching between GridItemsLayout and LinearItemsLayout. Done means the visible CollectionView updates its layout without restarting the app; verify the behavior on Windows with the reported size-change scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.