I've got a problem binding to a property on my model. In a DataGrid, I'm displaying Errors. Each error has the property ErrorDescription
which itself has the property Severity
.
I can bind to Severity
in the TextColumn of my DataGrid below, however binding to Severity
in the TemplateColumn fails with the error
"Cannot resolve property "ErrorDescription" in data context of type MainViewModel"
The DataContext my image-column is not the same as in my first text-column. Why is that?
<DataGrid ItemsSource ="{Binding Errors}" AutoGenerateColumns="False">
<DataGrid.Columns>
// works
<DataGridTextColumn Binding="{Binding ErrorDescription.Severity}"></DataGridTextColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image>
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
// Binding fails
<DataTrigger Binding="{Binding ErrorDescription.Severity}" Value="Unknown">
<Setter Property="Source" Value="/error.jpg"/>
</DataTrigger>
// Binding fails
<DataTrigger Binding="{Binding ErrorDescription.Severity}" Value="Ok">
<Setter Property="Source" Value="/ok.jpg"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>