我有一个 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>
列表和按钮的图片:
最佳答案
删除 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/