【问题标题】:How to display ListView inside the ListView in Xamarin.forms如何在 Xamarin.forms 的 ListView 中显示 ListView
【发布时间】:2020-01-28 12:57:23
【问题描述】:

我的响应数据看起来像这样的虚拟数据:

{
    "MsgCode": null,
    "IsError": false,
    "IsPartialError": false,
    "Message": [],
    "Data": {
        "TrackUpdates": [{
                "VersionId": 3,
                "VersionNumber": "15.2",
                "PublishedDate": "2020-01-20T00:00:00.000Z",
                "UpdatesName": [{
                        "UpdateId": 4,
                        "UpdateName": "Login issue fixes"
                    },
                    {
                        "UpdateId": 3,
                        "UpdateName": "Profile added"
                    }
                ]
            },
            {
                "VersionId": 2,
                "VersionNumber": "15.1",
                "PublishedDate": "2019-12-15T00:00:00.000Z",
                "UpdatesName": [{
                        "UpdateId": 2,
                        "UpdateName": "Token related changes"
                    },
                    {
                        "UpdateId": 1,
                        "UpdateName": "Design updates"
                    }
                ]
            }
        ]

    },
    "Pagination": null
}

如何使用 xamarin 表单显示此内容?

主要问题是显示内部列表。如果存在格式问题,请检查此图像。 JsonOutputImage

【问题讨论】:

  • 使用分组列表视图

标签: c# listview xamarin xamarin.forms


【解决方案1】:

我猜你可以在 Listview 中使用 Listview,如下所示。

<ListView x:Name="contactList" ItemsSource="{Binding PlatformsList}" SeparatorVisibility="Default"
             VerticalOptions="Center" HorizontalOptions="Center" WidthRequest="150">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <Label Text="Nested List" />
                    <ListView x:Name="contactNestedList" ItemsSource="{Binding BindingContext.PlatformsList, Source={x:Reference contactList}}" HeightRequest="300" BackgroundColor="Yellow" WidthRequest="150">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout Orientation="Horizontal">
                                        <CheckBox IsChecked="{Binding IsChecked}" VerticalOptions="Center" />
                                        <Label TextColor="Red" Margin="10,0" Text="{Binding PlatformName}" IsEnabled="{Binding IsChecked}" VerticalOptions="Center" />
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

但是,不建议在 ListView 中使用 ListView。如果以防万一,如果您的嵌套列表是一个已定义的列表,其中只有一组固定的项目,那么您可以使用 BindableLayout 而不是嵌套的 Listview。即只需将父 ListView 内的 ListView 替换为 BindableLayout。

如果您对使用 BindableLayout 有任何疑问,请查看我的以下博客以了解更多信息。

https://xdevlogs.com/2020/01/04/bindable-layout-xamarin-forms/

希望对你有帮助……

【讨论】:

  • 如果我的回复对您有帮助,请记得将我的回复标记为答案。谢谢...
猜你喜欢
  • 1970-01-01
  • 2014-12-26
  • 2018-05-28
  • 2016-07-31
  • 1970-01-01
  • 2019-12-11
  • 1970-01-01
  • 2014-11-06
  • 1970-01-01
相关资源
最近更新 更多