【发布时间】:2017-04-15 03:16:23
【问题描述】:
我正在尝试在 Xamarin 表单中使用列表视图,这是我的代码
<StackLayout x:Name="stackMap" Grid.Row="1">
<Label Text="Seleziona cantiere" Margin="7,0,0,0" TextColor="#3880c4" HorizontalTextAlignment="Start" FontSize="Medium" />
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<!--<Image Source="{Binding image}" />-->
<Label Text="{Binding Name}" TextColor="#f35e20" />
<Label Text="{Binding Type}" TextColor="#503026" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
以及加载方法中的代码隐藏:
var cities = new List<VeggieViewModel>();
cities.Add(new VeggieViewModel { Name = "okkk", Type = "okkk", Image = "okkkk" });
cities.Add(new VeggieViewModel { Name = "okkk", Type = "okkk", Image = "okkkk" });
cities.Add(new VeggieViewModel { Name = "okkk", Type = "okkk", Image = "okkkk" });
cities.Add(new VeggieViewModel { Name = "okkk", Type = "okkk", Image = "okkkk" });
cities.Add(new VeggieViewModel { Name = "okkk", Type = "okkk", Image = "okkkk" });
listView.ItemsSource = cities;
类对象:
public class VeggieViewModel
{
public string Name;
public string Type;
public string Image;
}
我的问题是它不会在列表视图中打印任何内容,我可以正确打印并生成他在里面的项目的列表视图,但不打印任何内容。 我哪里做错了?
解决方案
对不起,我分心的错误:(
解决办法是把{get; set;}对象类。
谢谢你们。
我仍然把问题留给像我这样分心的人:)
【问题讨论】:
-
请将解决方案添加为答案并将其标记为已接受
-
我已经添加了答案。
标签: c# listview xamarin xamarin.forms xamarin.forms.listview