1

How UWP's GridView auto performace

The data source: IEnumerable.

In PC, when the window's width is 1000,the column is 10;

when the window's width is 500,the column will be 5;

MAUI's CollectionView

CollectionView uses the ItemsLayout property to set the span value, so that the control can display the column to display. But when I change the width of the window in PC, the items wouldn't move.

It seems to be designed for only using in mobile devices. The Windows won't change size.

Then I tried to set the span value in code:

private void Button_Clicked (object sender , EventArgs e)
{
    var layout = collectionView.ItemsLayout as GridItemsLayout;
    layout.Span += 2;
}

I use the code above to change the volumn value, however, It doesn't work.

So, how can CollectionView change the span value?

One of the possible ways is to use the Trigger(I guess, I'm new to MAUI). Then call the control method like "UpdateVisual()" (I guess).

Florian
  • 1,019
  • 6
  • 22

1 Answers1

0

I am guessing the reason this did not work was that you were changing the Span on runtime which would probably not notify the UI. What you should be doing instead is reinitializing it, something like:

collectionView.ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical);
halfer
  • 19,824
  • 17
  • 99
  • 186
FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • It still doesn't work, the UI perhaps need some inside special method to invoke the changes – 大江东去fff Dec 16 '22 at 10:37
  • As a test, does it update if (after changing Span) you set itemssource to null, then back: `var holdItems = collectionView.ItemsSource; collectionView.ItemsSource = null; collectionView.ItemsSource = holdItems;`? – ToolmakerSteve Dec 17 '22 at 02:01