c# - Can't binding ObservableCollection to ListView by MVVM -
on xamarin form, has rows data no content , display 1 row , empty.
in model :
public class item { public string kind { get; set; } public string etag { get; set; } public string id { get; set; } public snippet snippet { get; set; } public contentdetails contentdetails { get; set; } public status status { get; set; } public statistics statistics { get; set; } } public class rootobject { public string kind { get; set; } public string etag { get; set; } public string nextpagetoken { get; set; } public pageinfo pageinfo { get; set; } public list<item> items { get; set; } } in viewmodel
private observablecollection<trendingmodel.rootobject> _trendingroots; private readonly itrendingservice _trendingservice; public observablecollection<trendingmodel.rootobject> trendingroots { { return _trendingroots; } set { _trendingroots = value; raiseprotertychanged(()=>trendingroots); } } ......
trendingroots = new observablecollection<trendingmodel.rootobject>(ridesresult); the results 'tredingroots' -> trendinroot[0].items[i].snippet..... on view, listview :
<listview x:name="lsthome" itemssource="{binding trendingroots}"> <listview.itemtemplate> <datatemplate> <viewcell> <stacklayout orientation="horizontal"> <image source="{binding items.snippet.thumbnails.medium}" aspect="aspectfit" widthrequest="220" heightrequest="220" horizontaloptions="center" verticaloptions="center" /> <label text="{binding items.snippet.title}" horizontaloptions="center" verticaloptions="center"> </label> </stacklayout> </viewcell> </datatemplate> </listview.itemtemplate> </listview> the final result listview has 1 item , item empty, in while,
- the result must have 15 items.
- display each item on listview item(currently empty, can't binding)
<listview x:name="lsthome" itemssource="{binding trendingroots[0].items}"> <listview.itemtemplate> <datatemplate> <viewcell> <stacklayout orientation="horizontal"> <image source="{binding snippet.thumbnails.medium}" aspect="aspectfit" widthrequest="220" heightrequest="220" horizontaloptions="center" verticaloptions="center" /> <label text="{binding snippet.title}" horizontaloptions="center" verticaloptions="center"> </label> </stacklayout> </viewcell> </datatemplate> </listview.itemtemplate> </listview>
Comments
Post a Comment