This repo is to show how a CollectionView in .NET MAUI contains default spacing between items even though it says in the documentation that it shouldn't.
Reporduction Steps:
- Create a new .NET MAUI project
- Remove the default MainPage.xaml content and replace with the following:
<Grid RowDefinitions="*"
ColumnDefinitions="*">
<CollectionView Grid.Row="0" Grid.Column="0"
ItemsSource="{Binding Strings}"
BackgroundColor="Red">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:MainPage">
<Label Text="{Binding .}"
TextColor="Black"
FontSize="14"
BackgroundColor="Yellow"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
- Remove the default MainPage.xaml.cs code behind and replace with the following:
public partial class MainPage : ContentPage
{
public List<string> Strings { get; set; }
public MainPage()
{
InitializeComponent();
Strings = new();
AddStrings();
BindingContext = this;
}
void AddStrings()
{
for (var i = 0; i < 10; i++)
{
Strings.Add("CollectionView shouldn't have spacing between items");
}
}
}
- Run the application
In my example I have set the CollectionView background to Red and the Label's to Yellow to clearly show where the spacing occurs.
You can see in this example that the Labels have space between then, even though in the documentation it says:
Example of application running