I have a data grid where in i have to display an image and again a datagris which has to display messages. I could bind the parent datagrid and image is getting displayed but the inner datagrid is not bound and neither displaying any error.
Am i missing anything? Here is my xaml
<DataGrid Grid.Column="0" AutoGenerateColumns="False" Width="Auto" ItemsSource="{Binding Col1}" ScrollViewer.VerticalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTemplateColumn Width="SizeToCells" Header="Column1" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<StackPanel Orientation="Vertical" >
<Image Source="{Binding ImagePathItem1}" Height="20" Width="20"/>
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Height="250" Width="250">
<DataGrid.Columns>
<DataGridTemplateColumn Width="SizeToCells" Header="Column2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding MessageData}" Foreground="Orange"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
The Col1 collection is bound to parent datasource and the data is available for all other controls.
I think you are misinterpreting what is the binding and in your example, the binding expression is incomplete:
ItemsSource="{Binding}".As you said in your comment,
Col1is anObservableCollection<MyCollectionClass>. What would be interesting to see is the class itself, but anyway.When you bind Col1 to your parent DataGrid, the properties of the class are available to the child controls for binding (for each item in your collection). If there is again no such Col1 property in MyCollectionClass, you can’t bind it to the inner DataGrid !
Imagine you have the following class (simplified):
You can then bind this way:
For each instance of your class in your collection, you’ll have a row in your DataGrid with Firstname and Lastname because they are public properties of the class. But not with Col1.