Reputation: 3417
I'm trying to use the listview in Xamarin forms, here is my code
<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:
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 :)
Upvotes: 0
Views: 1645
Reputation: 3417
Add {get; set;}
; this solution works:
public class VeggieViewModel
{
public string Name {get; set;}
public string Type {get; set;}
public string Image {get; set;}
}
Upvotes: 0
Reputation: 1
public class VeggieViewModel
{
public string Name {get; set;}
public string Type {get; set;}
public string Image {get; set;}
}
Upvotes: 0