Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 views
in Technique[技术] by (71.8m points)

xaml - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...