在Xamarin表单上,有行数据但没有内容,只显示一行而且为空。
在模特:
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; }
}
在ViewModel中
private ObservableCollection<TrendingModel.RootObject> _trendingRoots;
private readonly ITrendingService _trendingService;
public ObservableCollection<TrendingModel.RootObject> TrendingRoots
{
get { return _trendingRoots; }
set
{
_trendingRoots = value;
RaiseProtertyChanged(()=>TrendingRoots);
}
}
...
TrendingRoots = new ObservableCollection<TrendingModel.RootObject>(ridesResult);
结果是'TredingRoots' - &gt; TrendinRoot [0] .items [I]是.snippet ..... 在视图上,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>
最终结果是listview有1个项目,此项目为空,同时,
答案 0 :(得分:1)
<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>