c# - ListView 无法使用 Xamarin Forms 正确呈现

标签 c# xaml listview xamarin xamarin.forms

自从我上次为移动设备做一些开发以来已经有一段时间了。现在,我正在尝试使用 Xamarin Forms 更新我的知识。

我创建了一个 Xamarin Froms 项目。但是,我在将数据集合呈现为 ListView 内容时遇到了一些问题。我只能看到树标签的第一个元素。

这是 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"
             x:Class="ExampleBooks.View.BooksView"
             Title="Books">

  <ScrollView>
    <StackLayout>
      <ListView x:Name="ListViewBooks"
              ItemsSource="{Binding Books}">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <ViewCell.View>
                <StackLayout Padding="10" Orientation="Vertical">
                  <Label Text="{Binding Title}" FontSize="Large" VerticalOptions="Center"></Label>
                  <Label Text="{Binding Author}" FontSize="Small"></Label>
                  <Label Text="{Binding Description}" FontSize="14"></Label>
                </StackLayout>
              </ViewCell.View>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
    </StackLayout>
  </ScrollView>
</ContentPage>

这是使用上述代码呈现数据的屏幕截图:

Screenshot ListView

如您所见,AutorDescriptionLabels 没有显示。据我所知,应该显示 ListView 中嵌套 StackLayout 内的所有树元素。但是,我只能看到第一个。

我尝试使用 Padding 和 Spacing 属性。但是,它们似乎都没有帮助。

我在这里遗漏了什么吗?任何帮助/线索都会有所帮助。

PD我正在使用 Android 模拟器。但是,Windows Phone 模拟器中也会发生同样的情况。

谢谢

最佳答案

增加ListViewRowHeight:

<ListView x:Name="ListViewBooks"
          ItemsSource="{Binding Books}"
          RowHeight="100">

enter image description here

关于c# - ListView 无法使用 Xamarin Forms 正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39677592/

相关文章:

c# - 有什么方法可以使电子邮件的主题加粗吗?

c# - 将序列化对象迁移到新版本

wpf - 具有圆形和降级背景的 StackPanel

java - 点击小部件打开应用程序

android - 删除 Sugar ORM 数据库表记录

c# - 如何使用 .net compact framework 3.5 隐藏数据网格中的列

c# - Windows 应用商店应用程序自动导航到下一页失败

c# - 为什么我的 ItemsControls 中的项目不水平布局?

c# - 增加 MenuItem.Icon WPF 的大小

android - ListView 的第一个条目对于 RTL 总是不正确