私はそれが私が逃した単純な何かでなければならないことを知っています。データサービスを使用して、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}"/>
提案?
さらに調査した後:
わかりました、それは複雑なオブジェクトとは何の関係もありません。このコードでも2行が表示されますが、データは表示されません。私は何が欠けていますか?
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>