c# - 如何在 xamarin.forms 中隐藏 ListView 的空行

标签 c# xaml listview xamarin.forms portable-class-library

我有一个 StackLayout 和一个 ListView,我有一个添加按钮,我想在 ListView 下显示它。但是 ListView 显示了许多未使用的行。只是空行,这迫使我的按钮显示在页面底部。我整天都在弄乱 VerticalOptions,但无法让行消失。

这是我的 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:LiquitMobileApp"
             x:Class="LiquitMobileApp.MainPage"
             Title="Settings"
             >

    <StackLayout BackgroundColor="LightGray">
        <Label Text="Liquit Zones" TextColor="Gray" FontSize="Small" Margin="10"/>
        <StackLayout AbsoluteLayout.LayoutBounds="10,10,10,10">
            <ListView x:Name="UsingZone" SeparatorColor="LightGray" ItemTapped="ZonesList_ItemTapped" RowHeight="60" BackgroundColor="Green"  >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.ContextActions>
                                <MenuItem Clicked="OnEdit" Text="Edit" />
                                <MenuItem Clicked="OnDelete" CommandParameter="{Binding .}" Text="Trash" IsDestructive="True" />
                            </ViewCell.ContextActions>
                            <StackLayout Padding="15, 5, 0, 0" Orientation="Horizontal" BackgroundColor="White">
                                <Image Source="{Binding Image}" HorizontalOptions="Start" AbsoluteLayout.LayoutBounds="250.25, 0.25, 50, 50 "/>
                                <StackLayout Orientation="Vertical">
                                <Label Text = "{Binding Name}" FontSize="20" TextColor="Black" AbsoluteLayout.LayoutBounds="0.25, 0.25, 400, 40"/>
                                <Label Text = "{Binding Address}" TextColor="LightGray" AbsoluteLayout.LayoutBounds="50, 35, 200, 25"/>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.Footer>
                    <Label />
                </ListView.Footer>
            </ListView>
            <Button Text="Add Zone" TextColor="Black" HorizontalOptions="FillAndExpand" FontSize="Medium" Clicked="Button_Clicked" BackgroundColor="White"/>
        </StackLayout>
    </StackLayout>
</ContentPage>

列表和按钮的图片:

Picture of the list and the add-button

最佳答案

删除 ListView 的空行的一种简单方法是为 ListView 设置一个空的页脚。

ListView HeaderList = new ListView()
    {
       Footer = ""
    };

或在 XAML 中

<ListView  x:Name="HeaderList" Footer=""></ListView>

关于c# - 如何在 xamarin.forms 中隐藏 ListView 的空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44501196/

相关文章:

c# - 在 Microsoft Bot Framework V3 中触发系统消息

c# - 在 userfiles 文件夹中创建一个文件(C#、Windows 窗体)

android - 单击 ListView

android - SectionIndexer 如何影响 Android 快速滚动?

c# - WPF MeasureOverride 和 ArrangeOverride

c# - 打开按钮上的 View ,单击MVVM

c# - XAML 分组的 GridView/语义缩放不显示所有子项?

c# - WPF UI 线程被大集合阻塞

java - 线程问题 : NullPointerException

c# - 使用 .Net 如何使用 Sort 方法对数组进行反向排序,即从 Z 到 A?