Xamarin Listview StackLayout space between items

I am trying to display a list containing some elements, and I just want to give a little space between these elements.

I will tell you about this, but I could not find the answer that worked for me. Here is a solution that I found that has the same result as I did, but did not work: https://stackoverflow.com/a/165189/

I am using xamarin forms 2.3.2.127, and I would like to leave xaml for that.

My xaml code:

<pages:MainXaml.Content>
<ListView x:Name="AccountsList"
          ItemsSource="{Binding Items}"
          SeparatorVisibility="None"
          BackgroundColor="Gray">
  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <ViewCell.View>
          <StackLayout BackgroundColor="White" Margin="0,0,0,20" >
            <Label Text="{Binding Name}"
                 VerticalTextAlignment="Center"
                 LineBreakMode="TailTruncation"
                   />
            <Label Text="{Binding Amount}"
                   VerticalTextAlignment="Center"
                   LineBreakMode="TailTruncation"/>
          </StackLayout>
        </ViewCell.View>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>
</pages:MainXaml.Content>

I tried at intervals, Padding and Marging, none of them worked.

Visual Result / Expected:

enter image description here

thank

+4
source share
2 answers

, HasUnevenRows = True. Grid, " > " ​​:

<ListView xmlns="http://xamarin.com/schemas/2014/forms"
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
          x:Class="ConsumerBanking.UserControls.AccountsListView"
          SeparatorVisibility="None"
          BackgroundColor="Transparent"
          HasUnevenRows="True" >

  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <ViewCell.View>

          <Grid BackgroundColor="White" Margin="0,0,0,1" >
            <Grid.RowDefinitions>
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackLayout Grid.Column="0" Margin="10,5,0,5">
              <Label Text="{Binding Name}"
                     VerticalTextAlignment="Center"
                     LineBreakMode="TailTruncation"/>
              <Label Text="{Binding Amount}"
                     VerticalTextAlignment="Center"
                     LineBreakMode="TailTruncation"
                     FontSize="Large"/>
            </StackLayout>

            <Label Text=">" Grid.Column="1" VerticalTextAlignment="Center" Margin="0,0,20,0"
                   FontSize="Large" TextColor="{StaticResource darkGray}"/>
          </Grid>
        </ViewCell.View>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>
+3

Source: https://habr.com/ru/post/1655099/


All Articles