So i got this DataGrid in which i manually defined all the columns:
<DataGrid AutoGenerateColumns="False" <lotsofstuff> ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="firstname" x:Name="firstname" Binding="{Binding Path=firstname}" />
<DataGridTextColumn Header="lastname" x:Name="lastname" Binding="{Binding Path=lastname}" />
<DataGridCheckBoxColumn Header="sick" x:Name="sick" Binding="{Binding Path=sick}"/>
<DataGridCheckBoxColumn Header="vacation" x:Name="vacation" Binding="{Binding Path=vacation}" />
</DataGrid.Columns>
</DataGrid>
Filling it with a datatable works fine so far:
DataGrid.ItemsSource = DataTable.DefaultView;
But in my datatable exists is a 5th bool column and i want my DataGrid to display a certain picture if it’s true and another one if it’s false.
How do i do that? I have no clue.
Create a
DataGridTemplateColumnwith anImagewithin theCellTemplate. The ImageSourceproperty will be a binding expression, something like this:Create an implementation of
IValueConverterforDataToImageConverter(for example) to take the DataItem {Binding} – which will include your bool value, and within the converter you can return whatever image you like.