[英]bind custom list of items in a listview Xamarin forms
I'm trying to use the listview in Xamarin forms, here is my code 我正在尝试以Xamarin形式使用listview,这是我的代码
<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>
and the codebehind in load method: 以及load方法中的代码:
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;
the class object: 类对象:
public class VeggieViewModel
{
public string Name;
public string Type;
public string Image;
}
my poblem is that it does not print anything in the listview, I print properly and produces the list view of the items he has inside, but does not print anything. 我的难题是,它不会在列表视图中打印任何内容,我可以正确打印并生成他内部具有的项目的列表视图,但不打印任何内容。 Where am I doing wrong ?
我在哪里做错了?
SOLUTION sorry for my mistake of distracting :( the solution is to put {get; set;}
Object Class. thank you all. Still I leave the question for another distracted like me :) 解决方案对不起我分散注意力的错误:(解决方案是放入
{get; set;}
对象类。谢谢大家。我还是把这个问题留给另一个像我一样分散注意力的问题:
Add {get; set;}
添加
{get; set;}
{get; set;}
; {get; set;}
; this solution works: 此解决方案有效:
public class VeggieViewModel
{
public string Name {get; set;}
public string Type {get; set;}
public string Image {get; set;}
}
public class VeggieViewModel
{
public string Name {get; set;}
public string Type {get; set;}
public string Image {get; set;}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.