簡體   English   中英

如何在 Xamarin.forms 中的 ListView 中顯示 ListView

[英]How to display ListView inside the ListView in Xamarin.forms

我的響應數據看起來像這個虛擬數據:

{
    "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 表單顯示此內容?

主要問題是顯示內部列表。 如果有格式問題,請檢查此圖像。 JSON輸出圖像

我猜你可以在 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/

我希望它有幫助...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM