XF 列表视图绑定集合

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App29
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();
            var cities = new List<City>()
            {
                new City{ Name="beijing", State="bj"},
                new City{ Name="shanghai",State="sh"},
                new City{ Name="guangzhou",State="gz"},
                new City{ Name="shenzhen",State="sz"},
            };
            var dataTemplate = new DataTemplate(typeof(TextCell));
            dataTemplate.SetBinding(TextCell.TextProperty, "Name");
            dataTemplate.SetBinding(TextCell.DetailProperty, "State");
            myListView.ItemTemplate = dataTemplate;
            myListView.ItemsSource = cities;
  }
 }
}
posted @ 2018-08-07 20:18  dxm809  阅读(108)  评论(0编辑  收藏  举报