If two labels are inserted in succession, a certain space is formed between them, but I need to remove this space so that the texts of the first and second practically touch each other. Already tried everything: I asked them HeightRequest, and put each Label in their own separate StackLayout and asked the HeightRequest StackLayout, put Margin = "0", Padding = "0", VerticalOptions = "FillAndExpand" everywhere, Spacing = "0", but the problem could not be solved.

<StackLayout> <ListView HasUnevenRows="True" ItemsSource="{Binding DataItems}" SelectedItem="{Binding PickEvent, Mode=TwoWay}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout Padding="0"> <StackLayout HeightRequest="10" Padding="0" Margin="0" Spacing="0" VerticalOptions="FillAndExpand"> <Label Text="{Binding Date}" Margin="0" Style="{StaticResource Grey}" VerticalOptions="FillAndExpand" /> </StackLayout> <StackLayout HeightRequest="10" Padding="0" Margin="0" Spacing="0" VerticalOptions="FillAndExpand"> <Label Text="{Binding Title}" Margin="0" Style="{StaticResource h1}" VerticalOptions="FillAndExpand" /> </StackLayout> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout> 

Tell me how to solve the problem, if at all possible?

  • What is StackLayout? From a third-party library? In standard containers there is no such thing. And you did not try to put these Label in one container? Like your StackLayout, but together? ` - Ackbar
  • @Ackbar StackLayout is an Xamarin container. Yes, I tried, initially it was, this code is already the last modified version, which also does not work as expected. - Leo
  • @Alias ​​is the author above and wrote that he was not helped by setting Spacing to zero - Ackbar
  • 2
    Oh, guys, Spacing = "0" really helped. In the code from my example there is StackLayout, two more StackLayout are embedded in it and in each of them there is a label. So I assigned Spacing = "0" with this nested StackLayout, but not my parent, but since I didn’t quite understand what Spacing was and didn’t prescribe. Googled for "xaml label height", so I did not find the answer) - Leo

1 answer 1

Solution: Spacing = "0" for StackLayout. My problem is solved by the following code:

 <StackLayout Padding="0" Margin="0" Spacing="0"> <Label Text="{Binding Date}" Margin="10,0,10,0" HeightRequest="12" Style="{StaticResource Grey}" /> <Label Text="{Binding Title}" Margin="10,0,10,0" HeightRequest="14" Style="{StaticResource h1}" /> </StackLayout>