Xamarin.Forms ListView size to content?

前端 未结 4 1855
星月不相逢
星月不相逢 2020-12-31 09:10

I have a pretty large form (adapted mainly for tablets), that has a TabbedPage nesting a ScrollView and a vertical StackPanel containi

4条回答
  •  Happy的楠姐
    2020-12-31 09:51

    Ok Assume your ListView is Populated with NewsFeeds, lets use an ObservableCollection to contain our data to populate a ListView as Below :

    XAML Code :

    
    

    C# Code

    ObservableCollection  trends = new ObservableCollection();
    

    Then you assign the trends List to the ListView :

    newslist.ItemSource = trends;
    

    Then , we have make some Logic on the ListView and the data , So that the ListView Wraps the data , as the data increases the ListView also increases and viceversa :

    int i = trends.Count;
    int heightRowList = 90;
    i = (i * heightRowList);
    newslist.HeightRequest = i;
    

    Therefore the complete code is :

    ObservableCollection  trends = new ObservableCollection();
    newslist.ItemSource = trends;
    int i = trends.Count;
    int heightRowList = 90;
    i = (i * heightRowList);
    newslist.HeightRequest = i;
    

    Hope it Helps .

提交回复
热议问题