public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); List <Country> countryList = new List<Country>() { new Country(){Name="中国",ProvinceList=new List<Province>(){new Province() { Name = "四川省", CityList =new List<City> (){ new City() { Name = "绵阳市" }, new City() { Name = "成都市" } } }, new Province() { Name = "河南省", CityList =new List<City> () { new City() { Name = "鹤壁市" }, new City() { Name = "郑州市" } } } } }, new Country(){ Name="加拿大",ProvinceList=new List<Province>() {new Province() { Name="安图略",CityList =new List<City> () { new City() { Name = "南安大略省" }, new City() { Name = "北安大略省" } } }} } }; this.textBox1.SetBinding(TextBox.TextProperty, new Binding("/Name") { Source = countryList });//集合默认元素,即中国 this.textBox2.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList/Name") { Source = countryList }); this.textBox3.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList/CityList[1].Name") { Source = countryList }); } public class City { public string Name { get; set; } } public class Province { public string Name { get; set; } public List<City> CityList { get; set; } } public class Country { public string Name { get; set; } public List<Province> ProvinceList { get; set; } } } }
标签:City,set,Name,P91,List,Path,new,WPF,public From: https://www.cnblogs.com/yuanyuanhi/p/17554676.html