简体   繁体   English

Xamarin.Forms创建自定义对象以显示为列表

[英]Xamarin.Forms creating custom objects to display as a list

I'm fairly new to mobile development in C#, but I decided to dive into Xamarin.Forms to develop for the three major platforms at once. 我对使用C#进行移动开发还不是很陌生,但是我决定深入研究Xamarin.Forms,以便一次为三个主要平台进行开发。 What I would like to do now is create a custom object that contains text, an image, and a button, and I would like to be able to create multiples of them depending on how many sets are present in my database. 我现在想做的是创建一个包含文本,图像和按钮的自定义对象,我希望能够根据数据库中存在的集合创建多个对象。 I aware of the ContentPage class and then saw that ContentView can only contain a single child element, so I'm not sure what type of class I would use in order to create a custom visual object. 我知道ContentPage类,然后看到ContentView只能包含一个子元素,因此我不确定为了创建自定义视觉对象将使用哪种类型的类。 Ideally, I'd like to be able to do something like the image below: 理想情况下,我希望能够执行以下图像: 在此处输入图片说明

Take a look at the ListView class ( API doc ). 看一下ListView类( API doc )。 It should do the trick. 它应该可以解决问题。 It's relatively straightforward to create a DataTemplate with a ViewCell that represents the UI for your collection of data objects, which you will then assign to the ListView's ItemsSource property. 创建带有ViewCellDataTemplate相对简单,该ViewCell代表数据对象集合的UI,然后将其分配给ListView的ItemsSource属性。 The result is a scrollable list that updates with your data source. 结果是一个可滚动的列表,该列表随您的数据源更新。

There are lots of benefits to using this component, including built-in pull-to-refresh , template re-use, and context actions . 使用此组件有很多好处,包括内置的“ 推入刷新” ,模板重用和上下文操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM