XF 列表视图绑定集合
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
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();
{
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;
}
}
}
{
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;
}
}
}