简体   繁体   中英

Listview inside listview Xamarin.Forms

I want to create listview inside listview. I tried below code, which is not working in Android, same code working perfectly in iOS

<local:CustomListview
          x:Name="ListView"
      ItemsSource="{Binding List1}" HasUnevenRows="True"
          >
          <local:CustomListview.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <StackLayout
                Orientation="Vertical">
                  <StackLayout Orientation="Horizontal">
                    <Label Text="{Binding Name}"></Label>
                    <Label Text="{Binding CreatedOn}"></Label>
                  </StackLayout>
                  <Label Text="{Binding Description}"></Label>

                  <StackLayout
                    Orientation="Horizontal"
                    >
                    <Label Text="{Binding Count}"></Label>
                    <Label Text="Likes(s)"></Label>
                  </StackLayout>

                    <StackLayout
                      Orientation="Vertical"
                      Padding="5, 0, 0, 0"
                    >
                        <local:CustomListview ItemsSource="{Binding List2}" HasUnevenRows="True">
                         <local:CustomListview.ItemTemplate>
                                <DataTemplate>
                                  <ViewCell>
                                    <StackLayout Orientation="Vertical">
                                      <Label Text="{Binding Description}"></Label>
                                      <StackLayout Orientation="Horizontal">
                                        <Label Text="{Binding CreatedBy}"></Label>
                                        <Label Text="{Binding CreatedOn}"></Label>
                                      </StackLayout>
                                    </StackLayout>
                                  </ViewCell>
                                </DataTemplate>
                         </local:CustomListview.ItemTemplate>
                      </local:CustomListview>
                    </StackLayout>      

                </StackLayout>
              </ViewCell>
            </DataTemplate>
          </local:CustomListview.ItemTemplate>


        </local:CustomListview>

Any suggestions?

I can't use group listview, since I need to arrange controls like Label in particular way. I am binding child listview as part of parent listview's ItemsSource. Above code is not working, its showing only parent listview, child listview is not displayed.

Listview inside a Listview is not a supported option. Listviews are designed to be the only root control on a page, mainly due to sizing and scrolling concerns.

Also the complexity of the page might cause poor performance.

Ideally I would suggest reworking your layout so that the repeated information is on another page. However if you want to continue on with this approach you should look at the RepeaterView in XLabs. Its basically an enhanced StackLayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM