I have
if (e.PropertyType == typeof(bool))
{
e.Column.Header = "Status";
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Status";
DataTemplate imageTemplate = new DataTemplate();
DataTrigger imageBoolTrigger = new DataTrigger();
Converter.BoolToImage boolToImage = new Converter.BoolToImage();
Uri trueImageURI = new Uri(@"pack://application:,,,/MonitorView_wpf;component/Images/Icons/check-mark-16.png", UriKind.RelativeOrAbsolute);
boolToImage.TrueImage.Source = new BitmapImage(trueImageURI);
imageBoolTrigger.Binding = new Binding { Converter = boolToImage, ConverterParameter = e.Column };
imageTemplate.Triggers.Add(imageBoolTrigger);
templateColumn.CellTemplate = imageTemplate;
e.Column = templateColumn;
}
but alas, its not working.
how do I use an image instead of the autogenerated checkbox?
my converter looks like this:
public class BoolToImage : IValueConverter
{
public Image TrueImage { get; set; }
public Image FalseImage { get; set; }
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (!(value is bool))
{
return null;
}
bool b = (bool) value;
if (b)
{
return this.TrueImage;
}
else
{
return this.FalseImage;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
my image does exist in the assemby, it's a png - ive tried all sorts of things, but never working.
thanks in advance
Too much behind-code for my liking, personally I would create a template for it in resources:
Then override it on creation:
I've just used an image here (effectively making the column read only) but it would work equally well with a templated checkbox.