2016-02-05 93 views
1

我想在listview裏面創建listview。我試着下面的代碼,這是不工作在Android中,相同的代碼在iOS中完美工作listview裏面的listview Xamarin.Forms

<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的一部分。上面的代碼不工作,它只顯示父級列表視圖,不顯示子列表視圖。

+0

爲什麼它在Android上「不工作」?你可以再詳細一點嗎? – Demitrian

回答

4

Listview內部的ListView不是受支持的選項。列表視圖旨在成爲頁面上唯一的根控件,主要是由於大小和滾動問題。

此外,頁面的複雜性可能會導致較差的性能。

理想情況下,我會建議重做您的佈局,以便重複信息在另一頁上。但是,如果您想繼續使用此方法,則應該查看XLab中的RepeaterView。它基本上是一個增強的StackLayout。

+0

「即使我同意您的答案的一般想法,但」Listviews被設計成爲頁面上唯一的根控件「是錯誤的。作爲一個概括,避免任何移動應用程序中的嵌套滾動控制。 –

+0

@StephaneDelcroix - 這是怎麼回事?如果我記得賈森史密斯的評論和克雷格鄧恩的單獨評論,那就是它的意圖。由於需要滾動和調整頁面的大小,因此最好只使用它的根元素。雖然我確實在一個可以工作的頁面上有多個列表視圖,但是Jason提到它並沒有真正的支持,因爲它可能會遇到很多問題。除非這種情緒在最近的更新中有所改變? –

+0

我想當你說只有根控制。這聽起來像是如果有一個頁面上的listview,你必須把所有東西放在listview中,這是不正確的。你的意思是在另一頁上重複的信息?你的意思是使用像contentview? – batmaci