I've got a DataGrid that Auto Generates it's columns.
In Code i implement The AutoGeneratingColumn Event, to set a certain template for my Translation Datatype:
private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if(e.PropertyType == typeof(Translation)){
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.CellTemplate = (DataTemplate)Resources["LanguageTemplate"];
e.Column = templateColumn;
}
}
DataTemplate:
<DataTemplate x:Key="LanguageTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name.ActualTranslation}" HorizontalAlignment="Stretch" Grid.Column="0"></TextBlock>
<Image Source="{lex:LocImage en}" Height="15" HorizontalAlignment="Right" Grid.Column="1" Visibility="{Binding Name.HasCurrentLanguage, Converter={StaticResource boolToVis}, ConverterParameter=true}" ></Image>
</Grid>
</DataTemplate>
Now a problem occured: The TextBlock is bound to Name Property. That works fine if the object to be displayed has a Name Property. But if i have Translation properties that are not named "Name" obviously no data is shown. How would i bind correctly to cover all Translation Items.