简体   繁体   English

绑定列表视图Xamarin表单中的自定义项目列表

[英]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.

相关问题 Xamarin Forms-如何在ListView中显示/绑定列表? - Xamarin Forms - how to display/Bind List in ListView? 在 Xamarin.Forms 中,如何绑定到自定义类列表、ListView 和打印自定义类属性? - In Xamarin.Forms, how to Bind to list of custom class, for ListView and print custom class properties? 如何在 Xamarin.Forms 中的 ListView 中绑定列表 - How to bind list inside ListView in Xamarin.Forms 区分加载到列表项与滚动事件Xamarin表单ListView的项目 - Differentiate items loading to list vs scroll event Xamarin forms listview Xamarin在ListView项上的表单AutomationId - Xamarin Forms AutomationId on ListView items Xamarin Forms ListView分组绑定问题 - Xamarin Forms ListView grouping bind issue 如何在 Xamarin Forms 中添加将数组绑定到 ListView - How To Add Bind An Array To ListView in Xamarin Forms 如何在Xamarin Forms中的另一个列表中获取列表并将其绑定到ListView中? - How to fetch list inside of another list and bind it inside ListView in Xamarin Forms? Xamarin Forms - 调用事件“ItemSelected”时使自定义单元格绑定到原始列表视图项目源 - Xamarin Forms - Make custom cell bind to original listview itemsource when calling event "ItemSelected" Xamarin.Forms ListView 中的项目之间的填充 - Padding between items in Xamarin.Forms ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM