Xamarin – CollectionView extra space for first and last item

Issue

Hello guys,

my question is if I’am able to add some extra space above first item and under last item in CollectionView in Xamarin.

I have items styled like card with rounded corners but at the moment it can’t be seen clearly because there is no space above first and under last item. Vertical space between them is okay with ItemSpacing property.

Solution

I will add screenshot here. The blackline is the exact place where I need space.

As jason said that you can add padding or Margin for Grid or stacklayout, then add CollectionView in this layout.

 <Grid Padding"20">
            <CollectionView ItemsSource"{Binding images}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Frame BorderColor"Black" CornerRadius"30">
                            <StackLayout>
                                <Image Source"{Binding imagepath}" />
                                <Label Text"{Binding text}" />
                            </StackLayout>
                        </Frame>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </Grid>

Answered By – Cherry Bu – MSFT

Leave a Comment