我有两个对象Exercise和Objective,每个Exercise都有一个Objective。 在后面的代码我设置在我的XAML中练习的DataGrid如何使用WPF将相关对象属性绑定到DataGridTemplateColumn中的TextBlock
dgExercicios.ItemsSource = Repositorio<Exercicio>.GetAll();
和的ItemsSource。
<DataGrid Name="dgExercicios" CellStyle="{StaticResource CellStyle}" CanUserSortColumns="True" CanUserResizeColumns="True" AutoGenerateColumns="False">
<DataGrid.Columns>
<!--This bind works (Exercice.Nome)-->
<DataGridTextColumn Header="Nome" Binding="{Binding Nome}" Width="200" />
<!--This bind DONT works (I Trying to bind to Exercise.Objective.Descricao)-->
<DataGridTemplateColumn Header="Objetivo" Width="80" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<StackPanel>
<TextBlock Text="{Binding Path=Objective.Descricao}" T />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
我想要做的就是物业Exercise.Objective.Descricao到TextBlock绑定的Exercice.Nome
另一个问题,就需要在这种情况下DataGridTemplateColumn?
在Visual Studio调试模式下,你的程序运行时,在“输出”窗口应包含错误消息用于绑定错误。你可以发表它说什么? –
@Hi Stephen Hewlett。我从来没有想过要看看输出窗口,如果事实上,它帮助了我很多,我最终发现可能的问题是(事实上)在EF中加载相关实体。 – Ewerton