首页 文章

使用Xamarin Forms无法正确呈现ListView

提问于
浏览
2

自从上次我为移动设备做一些开发以来,已经有一段时间了 . 现在,我正在尝试使用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

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

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

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

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

谢谢

1 回答

  • 2

    增加 ListViewRowHeight

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

    enter image description here

相关问题