Employee类
public class Employee { public string DisplayName { get; set; } public string Twitter { get; set; } public string ImageUri { get; set; } }后台赋值
List<Employee> Employees = new List<Employee>(); //添加数据 BindingContext = Employees;前端绑定对应属性名BindingContext已经赋值,ItemsSource直接绑定下来即可
<ListView x:Name="listView" ItemsSource="{Binding }"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout Orientation="Horizontal"> <Image Source="{Binding ImageUri}" WidthRequest="40" HeightRequest="40" /> <StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand"> <Label Text="{Binding DisplayName}" HorizontalOptions="FillAndExpand" /> <Label Text="{Binding Twitter}"/> </StackLayout> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>注意:Employee实不实现INotifyPropertyChanged接口,均可以展示,只是看你做不做双向绑定
https://github.com/zLulus/NotePractice/tree/dev3/Xamarin.Forms/XamarinDemo/XamarinDemo/XamarinDemo/CustomizingCell
转载于:https://www.cnblogs.com/Lulus/p/8179077.html
相关资源:自定义单元格绘制组件DataGridViewCellPainter