Xamarin.Forms如何使用Frame作为ListView的根元素?

How to use a Frame as the root element of a ListView in Xamarin.Forms?

我正在尝试在 Xamarin.Forms 内置的应用程序上为时间线实现类似卡片的记录列表,这是我或多或少需要复制的布局:

我想我很接近,我的代码后面有两条记录,我将它们作为 ItemSource 分配给 XAML 端的 listView,这是我目前的结果:

但是如您所见,元素根本没有显示在它们的框架内,如果我用 TextCells 或 ImageCells 替换表单控件,数据显示正常。这是我目前拥有的 XAML 代码:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage Title="AudioBitts" 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:AudioBitts"
    x:Class="AudioBitts.TimelinePage">

    <ListView x:Name="listView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell Height="300">
                    <Frame HasShadow="true" Margin="5">
                        <StackLayout>
                            <StackLayout Orientation="Horizontal">
                                <Image Source="{Binding UserAvatar}" />
                                <Label Text="{Binding UserName}" />
                            </StackLayout>
                            <Image Source="{Binding BittImage}" />
                        </StackLayout>
                    </Frame>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</ContentPage>

我为 XAML 代码提供的结构是否遗漏了什么?谢谢!

您可以设置ListView.RowHeight or set ListView.HasUnevenRow让数据完整显示。