I have a main object that has properties, each their own object:
Package {
Name
Date
}
Document {
Name
Package1 = Package()
Package2 = Package()
Package3 = Package()
Package4 = Package()
}
Now in WPF datagrid, I'd like to bind each column to one of the Document.PackageX properties. But the Name binding inside the DataTemplate always picks up the Document.Name and not the Package.Name
<DataTemplate x:Key="MyCellTemplate">
<Border>
<TextBlock Text="{Binding Name}" /> # this is Package.Name property
</Border>
</DataTemplate>
<DataGrid ItemsSource="{Binding ListOfDocuments}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Package 1" CellTemplate="{StaticResource MyCellTemplate}"/>
<DataGridTemplateColumn Header="Package 2" CellTemplate="{StaticResource MyCellTemplate}"/>
<DataGridTemplateColumn Header="Package 3" CellTemplate="{StaticResource MyCellTemplate}"/>
<DataGridTemplateColumn Header="Package 4" CellTemplate="{StaticResource MyCellTemplate}"/>
</DataGrid.Columns>
</DataGrid>
How should I set the context of a cell template to the nested object?
(Apologize for over-simplification but I thought it's easier to read and explains the core issue)