Looking for some guidance as to how to display an image correctly in a wpf datagrid whose columns are defined at runtime, I can’t define the columns in XAML.
My grids underlying collection contains an integer field that relates to a certain image.
I create a DataGridTextColumn column on my datagrid at runtime and bind it and set a converter.
Binding binding = new Binding("MyIntegerField");
binding.Converter = new Converters.IconIndexToImageConverter();
and my converter looks like this ;
public class IconIndexToImageConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
System.Drawing.Bitmap bitmap = null;
if (value != null)
{
int imageIndex = (int)value;
switch (imageIndex)
{
case 1:
return Properties.Resources.clip;
but in my grid I don’t see the image but see the type name, System.Drawing.Bitmap. All other bound fields are being displayed correctly.
I can see that the converter is being hit for this column, am I missing something on the binding?
Thanks….
Yes, in combination with a template which instantiates an
Imagecontrol, which has your image as itsSource, WPF works with theImageSourcebase class, you will need to convert theBitmap. Search SO, there already should be a question about that (theInteropclass may be helpful).