【问题标题】:How to use a Frame as the root element of a ListView in Xamarin.Forms?如何在 Xamarin.Forms 中使用 Frame 作为 ListView 的根元素?
【发布时间】:2017-09-04 15:02:09
【问题描述】:

我正在尝试在 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 代码提供的结构上是否遗漏了某些内容?谢谢!

【问题讨论】:

    标签: xaml listview xamarin.forms cardview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 2014-12-25
      • 1970-01-01
      • 2021-06-11
      相关资源
      最近更新 更多