我知道它一定是我错过的一些简单的东西。我使用数据服务将数据导入我的 silverlight 应用程序。当我将数据绑定到我的数据网格时,它就像一个魅力
LessonGrid.ItemsSource = context.Lessons
但是,一旦我尝试将对象包装到更复杂的数据结构中,它就会停止工作
LessonGrid.ItemsSource = context.Lessons.Select(l => new {Lesson = l; Color=Colors.Yellow})
我试图用路径和没有定义绑定并且似乎不起作用
<data:DataGridTextColumn Header="Date" Binding="{Binding StartTime}"/>
<data:DataGridTextColumn Header="Date" Binding="{Binding StartTime, Path=Lesson.StartTime}"/>
<data:DataGridTextColumn Header="Date" Binding="{Binding Path=Lesson.StartTime}"/>
<data:DataGridTextColumn Header="Date" Binding="{Binding StartTime, Path=Lesson}"/>
建议?
经过更多的研究:
好的,这与复杂的对象无关。即使此代码显示两行但没有数据。我错过了什么?
LessonGrid.ItemsSource =
new[] {new {Color = Colors.Yellow,StartTime = 12, Text="text"},
new {Color = Colors.Red, StartTime = 14, Text="text3"}};
xml:
<data:DataGrid x:Name="LessonGrid" AutoGenerateColumns="True" Height="375" IsReadOnly="True"> </data:DataGrid>