列表视图中的列表视图 Xamarin.Forms [英] Listview inside listview Xamarin.Forms

查看:25
本文介绍了列表视图中的列表视图 Xamarin.Forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表视图中创建列表视图.我尝试了下面的代码,这在 Android 中不起作用,相同的代码在 iOS 中完美运行

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>

有什么建议吗?

我不能使用组列表视图,因为我需要以特定方式排列像 Label 这样的控件.我将子列表视图绑定为父列表视图的 ItemsSource 的一部分.上面的代码不起作用,它只显示父列表视图,不显示子列表视图.

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 中的 Listview 不是受支持的选项.列表视图被设计为页面上唯一的根控件,主要是由于大小和滚动问题.

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.

理想情况下,我建议重新设计您的布局,以便重复的信息在另一个页面上.但是,如果您想继续使用这种方法,您应该查看 RepeaterView 在 XLab 中.它基本上是一个增强的 StackLayout.

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.

这篇关于列表视图中的列表视图 Xamarin.Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆