I found the following as a source of help towards the solution:
public class ImageConverter : IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new BitmapImage(new Uri((string)value, UriKind.RelativeOrAbsolute));
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
The path to the image is Images\File.bmp. I tried changing the formatting of the string to create a proper Uri, but the image STILL does not appear in the cell X| I found a solution which helped in better creating the path to be in the proper form of a Uri. What follows IS the solution:
public class ImageConverter : IValueConverter
{
public static BitmapImage CreateBMImage(string path)
{
BitmapImage bi = new BitmapImage();
try
{
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnDemand;
Uri baseUri = new Uri(Application.ResourceAssembly.Location);
bi.UriSource = new Uri(baseUri, path);
bi.EndInit();
}
catch
{
return null;
}
return bi;
}
public static Image CreateImage(string path)
{
Image img = new Image();
img.Source = CreateBMImage(path);
return img;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
return CreateBMImage((string)value);
}
catch
{
return new BitmapImage();
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new System.NotImplementedException();
}
}