gpt4 book ai didi

xamarin.forms.listview - 删除 xamarin 表单中 ListView 的空白空间

转载 作者:行者123 更新时间:2023-12-03 21:22:03 25 4
gpt4 key购买 nike

我正在为我的项目使用 xamarin.forms listview。设计如下:

<ContentView x:Name="Overlay" IsVisible="False"
VerticalOptions="Center" HorizontalOptions="Center" Margin="10,20,10,30"
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="LightGray">
<StackLayout Spacing="0">
<StackLayout Padding="20" BackgroundColor="#9C6114" Spacing="0">
<Label Text="Country Name" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"></Label>
</StackLayout>
<StackLayout Spacing="0">
<ListView x:Name="CountryList" HasUnevenRows="True" Margin="10,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Switch IsToggled="{Binding IsToggle}"></Switch>
<Label Text="{Binding CountryName}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout Orientation="Horizontal">
<Button x:Name="btncancel" Text="Cancel" TextColor="White" BackgroundColor="#9C6114" HorizontalOptions="CenterAndExpand" Clicked="btncancel_Clicked"></Button>
<Button x:Name="btnsubmit" Text="Submit" TextColor="White" BackgroundColor="#9C6114" HorizontalOptions="CenterAndExpand" Clicked="btnsubmit_Clicked"></Button>
</StackLayout>
</ListView.Footer>
</ListView>
</StackLayout>
</StackLayout>
</ContentView>

对于此 ListView , ListView 下方有空白空间。我无法删除 ListView 中的多余空格。请看附图。 enter image description here

请帮我解决这个问题。

最佳答案

我有一个类似的问题。我点击了这个链接:https://xamarinsharp.com/2017/05/20/xamarin-forms-listview-height-change-dynamically-using-mvvm-and-also-solve-empty-space-issue/

基本上,如果您还没有,则需要使用 MVVM 设置您的项目。在您的 XAML 中,您必须为 ListView 提供一个 HeighRequest 属性并将其值设置为:HeighRequest="{Binding Height}"。在您的 View 模型中,添加以下内容:

诠释_高度;

公共(public) int 高度

    {
get { return _height; }
set
{
_height = value;
OnPropertyChanged("Height");
}
}

然后,在您的 viewModel 的构造函数中(或者您设置 ListView 对象的任何位置),添加以下内容:
        Height = (**object**.Count * 60) + (**object**.Count * 10);

这对我来说很好!

关于xamarin.forms.listview - 删除 xamarin 表单中 ListView 的空白空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52774784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com