我知道它必须简单,我错过了。我使用数据服务将数据导入到我的Silverlight应用程序中。当我将数据绑定到我的DataGrid它在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"}};
XAML:
<data:DataGrid x:Name="LessonGrid" AutoGenerateColumns="True" Height="375" IsReadOnly="True"> </data:DataGrid>
为了澄清,StartTime是Lesson对象的属性。 – Vitalik 2009-11-18 12:05:07