How remove space under collectionview or Listview

AS_H 41 Reputation points
2021-07-08T08:46:31.923+00:00

Hi guys

How remove space under collectionview or Listview

I use Template Selector

 <ListView x:Name="Msg" BackgroundColor="Transparent"  Grid.Row="2" 
                              AutomationProperties.IsInAccessibleTree="True" 
                              ItemsSource="{Binding RepliesItems}" HasUnevenRows="True" 
                              ItemTemplate="{StaticResource TemplateSelector}" Margin="5,0,5,5">
                </ListView>
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,919 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Wang 5,511 Reputation points
    2021-07-09T01:38:46.29+00:00

    Hi ASH-1598,

    Welcome to our Microsoft Q&A platform!

    To remove the space under the Listview, you need to set the Margin to "5,0,5,0". The last number represents the height of the bottom thickness, so you need to set it to "0".

    Also, if you want to remove the space between the Grid.Rows, you can create a custom Style for Grid.

    According to the source code, we can know that the default value is 6 for both RowSpacing and ColumnSpacing. So setting RowSpacing and ColumnSpacing to 0 will remove the sapce immediately.

    Here is the xaml demo.

    <ContentPage.Resources>  
        <ResourceDictionary>  
            <Style TargetType="Grid" x:Key="CustomGrid">  
                <Setter Property="ColumnSpacing" Value="0" />  
                <Setter Property="RowSpacing" Value="0" />  
            </Style>  
        </ResourceDictionary>  
    </ContentPage.Resources>  
      
    <Grid RowDefinitions="*,*,*,*" Style="{StaticResource CustomGrid}">  
        <BoxView BackgroundColor="Red" VerticalOptions="FillAndExpand"/>  
        <BoxView Grid.Row="1" BackgroundColor="Yellow" VerticalOptions="FillAndExpand"/>  
        <ListView x:Name="Msg" BackgroundColor="Blue"  Grid.Row="2"   
                                AutomationProperties.IsInAccessibleTree="True"   
                                ItemsSource="{Binding RepliesItems}" HasUnevenRows="True"  
                                ItemTemplate="{StaticResource TemplateSelector}" Margin="5,0,5,0">  
        </ListView>  
        <BoxView Grid.Row="3" BackgroundColor="Green" VerticalOptions="FillAndExpand"/>  
    </Grid>  
    

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.