Home > Software design >  How do I add padding to a Xamarin Forms CollectionView?
How do I add padding to a Xamarin Forms CollectionView?

Time:09-17

The CollectionView in Xamarin Forms does not support the Padding Property. Therefore the last item in the collection can be hidden behind overlaying items higher in the z-stack, like floating action buttons. Is there a workaround for this?

CodePudding user response:

The best workaround I found is to use the Footer property of collectionview and add an empty, fixed height, transparent StackLayout to act as the missing padding.

<CollectionView  ItemsSource="{Binding Items}" ... >
      <CollectionView.Footer>
      <!--A fixed height footer,to simulate bottom padding and keep the last item in view when scrolling-->
      <StackLayout Padding="0,0,0,70" BackgroundColor="Transparent"/>
      </CollectionView.Footer>
</CollectionView>

CodePudding user response:

A simple workaround for that is to create a view that contains it, and create padding on this View. I think it is better than placing a footer.

CodePudding user response:

I wanted to use a floating button in a project but used the Footer also for a button. Then there is no problem with overlaying .

            <CollectionView.Footer>
            <StackLayout BackgroundColor="LightGray">
                <Button Margin="10,0,0,0"
                       Text="Friends of Xamarin Monkey"
                       FontSize="Small"
                       FontAttributes="Bold"
                        Clicked="Button_Clicked"/>
            </StackLayout>
        </CollectionView.Footer>
  • Related