I have a String to Img converter for displaying images in a DataGrid based on results of various methods that run, but for a reason I can't get my head around why my code can't find the images.
This is my converter, testing various different paths to PNGs that are all in /img/
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
BitmapImage image = null;
var str = value.ToString();
//TODO Use new icons
if (str == "pass")
{
image = new BitmapImage(new Uri("pack://application:,,,/img/Icon-Pass.png"));
}
if (str == "fail")
{
image = new BitmapImage(new Uri("/../img/Icon-Fail.png", UriKind.Relative));
}
if (str == "warning")
{
image = new BitmapImage(new Uri("../img/Icon-Warning.png", UriKind.Relative));
}
if (str == "notapplicable")
{
image = new BitmapImage(new Uri(@"/AppName;component/img/Icon-NonApplicable.png", UriKind.Relative));
}
return image;
}
My project's structure is:
AppRoot/
├─ Helpers/
│ ├─ ImgConverter.cs
├─ img/
│ ├─ Icon-Pass.png
│ ├─ Icon-Fail.png
│ ├─ Icon-Warning.png
│ ├─ Icon-NonApplicable.png
But with all of these I get a mixture of File not found, directory not found and cannot locate resource exceptions
I can only assume I'm missing something dumb obvious, but I think I'm too deep to see it.
Edit - Resolved For the pack Uris to work, the Buid action for the images must be set to "Resource". Thanks @KlausGütter :)