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 states = new List<State>()
{
new State("FL")
{
new City{ Name="beijing" },
new City{ Name="shanghai"}
},
new State("AL")
{
new City{ Name="guangzhou"},
new City{ Name="shenzhen"},
}
};
var dataTemplate = new DataTemplate(typeof(TextCell));
dataTemplate.SetBinding(TextCell.TextProperty, "Name");
myListView.IsGroupingEnabled = true;
myListView.GroupDisplayBinding = new Binding("Name");
myListView.GroupShortNameBinding = new Binding("Name");
//myListView.RowHeight = 100;
myListView.Header = "这是页眉";
myListView.Footer = "这是页脚";
myListView.SeparatorVisibility = SeparatorVisibility.Default;//在windows phone里面默认没有分割线,在android和Ios才有
myListView.SeparatorColor = Color.Red;
myListView.ItemTemplate = dataTemplate;
myListView.ItemsSource = states;
}
}
}
{
new State("FL")
{
new City{ Name="beijing" },
new City{ Name="shanghai"}
},
new State("AL")
{
new City{ Name="guangzhou"},
new City{ Name="shenzhen"},
}
};
var dataTemplate = new DataTemplate(typeof(TextCell));
dataTemplate.SetBinding(TextCell.TextProperty, "Name");
myListView.IsGroupingEnabled = true;
myListView.GroupDisplayBinding = new Binding("Name");
myListView.GroupShortNameBinding = new Binding("Name");
//myListView.RowHeight = 100;
myListView.Header = "这是页眉";
myListView.Footer = "这是页脚";
myListView.SeparatorVisibility = SeparatorVisibility.Default;//在windows phone里面默认没有分割线,在android和Ios才有
myListView.SeparatorColor = Color.Red;
myListView.ItemTemplate = dataTemplate;
myListView.ItemsSource = states;
}
}
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace App29
{
public class City
{
public string Name { get; set; }
}
{
public class City
{
public string Name { get; set; }
}
public class State : ObservableCollection<City>
{
public State(string name)
{
Name = name;
}
public string Name { get; set; }
}
}
{
public State(string name)
{
Name = name;
}
public string Name { get; set; }
}
}