Hi!
I'm trying to add an image column to the DataGrid (WPF, .Net 7) following the given examples, but it's not working as expected, my column is always empty.
Debugging, I see that the path to the image is correct and the Bitmap is correctly loaded.
I've tried to modify the converter to manage the cache OnLoad, but the result doesn't change.
Note: a strange thing, when I debug the converter, sometimes an image appears in the grid. If I disable the breakpoint and reload, the image disappers.
XAML
...
...
Model in C#
...
public string Flag { get; set; } = @".\Resources\Flags\uk.png";
...
CONVERTER
...
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
if (value != null)
{
string imagename = value as string;
var url = new Uri(string.Format(@"{0}", imagename), UriKind.Relative);
var bmp = new System.Windows.Media.Imaging.BitmapImage(url);
return bmp;
}
}
catch { }
return null;
}