0

我正在尝试在 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;}对象等级。谢谢大家。我还是把问题留给像我这样分心的人:)

4

2 回答 2

0

添加{get; set;}; 此解决方案有效:

 public class VeggieViewModel
    {
        public string Name {get; set;}
        public string Type {get; set;}
        public string Image {get; set;}
    }
于 2017-01-11T08:25:52.060 回答
0
 public class VeggieViewModel
{
    public string Name {get; set;}
    public string Type {get; set;}
    public string Image {get; set;}
}
于 2017-04-14T18:42:24.253 回答