windows phone ListBox 数据绑定的奇怪问题
public class MyDataClass { public MyDataClass(String name) { this._name = name; } private String _name ; public String Name { get { return this._name; } } } public MainPage() { InitializeComponent(); MemberInfo[] filedInfos = typeof(InputScopeNameValue).GetMembers(); MyDataClass[] datas = new MyDataClass[filedInfos.Length]; for (int i = 0; i < filedInfos.Length; i++) { MyDataClass myData = new MyDataClass(filedInfos[i].Name); datas[i] = myData; } [color=#FF0000] //正常显示数据 this.DataContext = datas; //不显示数据 //this.DataContext = filedInfos;[/color] }
<ListBox Height="500" Width="400" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name}" Foreground="Red" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>