I have two objects Exercise and Objective, each Exercise has one Objective.
In the code behind I set the ItemsSource of the Exercises DataGrid
dgExercicios.ItemsSource = Repositorio<Exercicio>.GetAll();
And in my XAML.
<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>
What I want to do is to bind the property Exercise.Objective.Descricao to the TextBlock on the Exercice.Nome
Another question, will a DataGridTemplateColumn be needed in this case?
Well it will work if the Exercise class has a property called Objective, and the Objective class has a property called Descricao.
And you don’t need a DataGridTemplateColumn if you just want to show a string: