请看下面一段代码,普通的datagrid绑定.
<sdk:DataGrid x:Name="dgTest"/>
List<User> ls = new List<User>()
{
new User{Name="wangjie",Age=12,Sex=true},
new User{Name="wangjie2",Age=12,Sex=true},
new User{Name="wangjie3",Age=12,Sex=false},
new User{Name="wangjie4",Age=12,Sex=true},
new User{Name="wangjie",Age=12,Sex=true}
};
dgTest.ItemsSource = ls;
{
new User{Name="wangjie",Age=12,Sex=true},
new User{Name="wangjie2",Age=12,Sex=true},
new User{Name="wangjie3",Age=12,Sex=false},
new User{Name="wangjie4",Age=12,Sex=true},
new User{Name="wangjie",Age=12,Sex=true}
};
dgTest.ItemsSource = ls;
关键是User类:
class User
{
public int Age { get; set; }
public string Name { get; set; }
public bool Sex { get; set; }
}
{
public int Age { get; set; }
public string Name { get; set; }
public bool Sex { get; set; }
}
这样得到的结果出乎我的意料: 没有数据???
无意间在class前加了public,这次DataGrid有数据了:
环境: Vs2010+silverlight4
是silverlight运行时的特点?还是只是DataGrid的特色?