MAUI CollectionView Linespacing

EuroEager2008 171 Reputation points
2022-05-27T20:00:01.577+00:00

On Windows a CollectionView has a default line spacing of 0 which does not look good on Windows at all (at least not with text items with default font etc.).
The visual line spacing is larger than the height of the text fonts which simply does not look good, at least not for my application (should be much more dense)
On Android emulator it looks ok.

Any way to fix this?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,593 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2022-05-30T07:49:37.853+00:00

    Hello,​

    As you said if you do not set the ItemSpacing property for CollectionView.ItemsLayout, this is by design that default line spacing is 0, please check this document: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/layout#item-spacing

    By default, there is no space between each item in a CollectionView

    >>The visual line spacing is larger than the height of the text fonts which simply does not look good,

    We can also see that in Windows platform that even if we have set the ItemSpacing is 0, line spacing still looks bigger than Andorid platform.
    May I know what is your desired layout? If you just want to have a smaller line spacing, maybe you can use FlexLayout control:

       <FlexLayout    
               Direction="Column"  
               BindableLayout.ItemsSource="{Binding Items}">  
               <BindableLayout.ItemTemplate>  
                   <DataTemplate>  
                       …  
                   </DataTemplate>  
               </BindableLayout.ItemTemplate>  
           </FlexLayout>  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.