如何在Xamarin表单中删除ListView中的Extra Separator

Har*_*iya 0 listview separator xamarin xamarin.forms

我是Xamarin Forms的新手.如果这是一个愚蠢的问题,请原谅我.

我创建了Simply ListView.但是我想删除哪一行有空的额外分隔符.

我尝试搜索SO,谷歌和Xamarin表格.但对我来说没有任何帮助.

Xaml代码:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ListViewDemo" x:Class="ListViewDemo.ListViewDemoPage">
    <StackLayout Orientation="Vertical"
             VerticalOptions="Fill"
             HorizontalOptions="StartAndExpand">
        <ListView x:Name="MainListView" Margin="0,30,0,0" VerticalOptions="FillAndExpand"  SeparatorColor="Red" BackgroundColor="Gray" HasUnevenRows="true">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Label Text="{Binding Name}" Grid.Column="0" Margin="10,10,0,0">
                            </Label>
                            <Label Text="{Binding Age}" Grid.Column="1" Margin="0,10,10,0">
                            </Label>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

ListViewDemoPage.cs

using System.Collections.Generic;
using Xamarin.Forms;

namespace ListViewDemo
{
    public partial class ListViewDemoPage : ContentPage
    {
        public ListViewDemoPage()
        {
            InitializeComponent();

            var strings = new List<EmptyClass>
            {
                new EmptyClass{Name = "Harshad Harshad Harshad Harshad Harshad Harshad Harshad Harshad", Age = 23},
                 new EmptyClass{Name = "Sunita", Age = 23},
                 new EmptyClass{Name = "Rahul", Age = 23},
                 new EmptyClass{Name = "Vrushbh", Age = 23},
                 new EmptyClass{Name = "Harmi", Age = 23},
                 new EmptyClass{Name = "Jigu", Age = 23},

            };

            MainListView.ItemsSource = strings; 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

EmptyClass.cs

using System;
namespace ListViewDemo
{
    public class EmptyClass
    {
        public string Name { get; set; }
        public double Age { get; set; }
        public EmptyClass()
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助都要得到赞赏.

Har*_*iya 6

只需在页面下方添加页脚 ListView.ItemTemplate

<ListView.Footer>
            <StackLayout Orientation="Horizontal">
            </StackLayout>
</ListView.Footer>
Run Code Online (Sandbox Code Playgroud)

完整代码:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ListViewDemo" x:Class="ListViewDemo.ListViewDemoPage">
    <ListView x:Name="MainListView" Margin="0,30,0,0" VerticalOptions="FillAndExpand" SeparatorColor="Red" BackgroundColor="Gray" HasUnevenRows="true">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <Label Text="{Binding Name}" Grid.Column="0" Margin="10,10,0,0">
                        </Label>
                        <Label Text="{Binding Age}" Grid.Column="1" Margin="0,10,10,0">
                        </Label>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.Footer>
            <StackLayout Orientation="Horizontal">
            </StackLayout>
        </ListView.Footer>
    </ListView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)