【发布时间】:2009-11-18 05:12:22
【问题描述】:
我知道它一定是我错过的一些简单的东西。我使用数据服务将数据导入我的 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 对象的一个属性。
标签: wpf silverlight data-binding wpfdatagrid