1

I can't set padding to 0 in items of CollectionView in MAUI.

In this example, I use Data and Data[i].Color as follow:

<CollectionView 
    ItemsSource="{Binding Data}" 
    ItemSizingStrategy="MeasureFirstItem"
    ItemsLayout="HorizontalList">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <Button 
                Clicked="Button_Clicked" 
                WidthRequest="10" 
                HeightRequest="10" 
                BackgroundColor="{Binding Color}" />
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

My Buttons has Width 10 and Height 10, and there is space between my Buttons. Only set Button Width more than 100 can I see no space between my Buttons, but 100 is too large.

I tried to set Padding or Margin in Button, and WidthRequest in CollectionView, but it didn't work.

How can I remove the space?

I tried ItemSpacing:

<CollectionView.ItemsLayout>
    <LinearItemsLayout 
        Orientation="horizonal"
        ItemSpacing="0" />
</CollectionView.ItemsLayout>

But fail.

lsyanling
  • 11
  • 3

1 Answers1

1

You want to set the space between buttons to 0 in CollectionView. And this is a known issue and it's been tracked in Windows CollectionView ItemSpacing is not working. When setting the property ItemSpacing to 0, the space between the items should have been reduced to 0, however it doesn't work as expected.

For more details, you can refer to MAUI: How to reduce spacing between buttons.

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15