【问题标题】:CardView in Xamarin.FormsXamarin.Forms 中的 CardView
【发布时间】:2017-09-03 06:11:26
【问题描述】:

我正在寻找一种方法来动态生成类似卡片的控件,如下所示:

我一直在进行一些搜索,发现 this article 向您展示了如何在 Xamarin.Android 项目上实现 CardView。但我使用的是 Xamarin.Forms,所以我也可以为 iOS 编译。

我还尝试使用带有 ViewCells 和几个 StackLayout 标签的 ListView,但甚至无法接近它,这里是代码:

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

我对 Xamarin 很陌生,所以如果我缺少一些基本的东西,请告诉我。

【问题讨论】:

标签: xamarin.forms cardview


【解决方案1】:

你在正确的轨道上。使用 ListView,以 Frame 作为根元素和边距,并根据需要设置 ListView 的背景颜色。这应该给你卡片的外观。然后根据需要填写卡片。

<ListView x:Name="listView" BackgroundColor="Gray">
    <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>

【讨论】:

  • 谢谢!我正在尝试不同的控件顺序/排列,但它只显示空白帧(每条记录 1 帧)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 1970-01-01
相关资源
最近更新 更多