日期:2014-05-18 浏览次数:20978 次
List<County> c_list = new List<County>(); City city = new City(); city.Name = "City"; Province p = new Province(); p.Name = "Province"; p.CityList = new List<City>() { city}; County c = new County(); c.Name = "County"; c.ProvinceList = new List<Province>() { p}; c_list.Add(c); this.txt_city.SetBinding(TextBox.TextProperty, new Binding("/Name") { Source=c_list}); this.txt_province.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList.Name") { Source = c_list }); this.txt_county.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList/CityList.Name") { Source = c_list });
<StackPanel> <TextBox x:Name="txt_city" Margin="5" BorderBrush="Red"/> <TextBox x:Name="txt_province" Margin="5" BorderBrush="Red"/> <TextBox x:Name="txt_county" Margin="5" BorderBrush="Red"/> </StackPanel>
this.txt_city.SetBinding(TextBox.TextProperty, new Binding("/Name") { Source = c_list }); this.txt_province.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList[0].Name") { Source = c_list }); this.txt_county.SetBinding(TextBox.TextProperty, new Binding("/ProvinceList[0].CityList[0].Name") { Source = c_list });