WPF Binding Image Soure

Marc Jeeves 386 Reputation points

Evening, I'm a little confused as to why this is not working i have a custom error handling window that has an image based on error, warning, information the model and view model(datacontext) are updating correctly and the binding path is correct but the image wont refresh

can anybody help

error message

Severity Count Data Context Binding Path Target Target Type Description File Line Project
Warning 1 SimpleNotification_ViewModel SimpleNotificationImagePath Image.Source, Name='Img_SimpleNotification' ImageSource Failed to convert value './Images/NikolaError.png' (type 'String') to the target type using converter 'TargetDefaultValueConverter'. The fallback value will be used if it's available. IOException:'System.IO.IOException: Cannot locate resource 'images/nikolaerror.png'.


Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,663 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Marc Jeeves 386 Reputation points

    So the mystery deepens, after reading a couple of posts i decided to convert it to a bitmap and bind to a bitmap property,

    it still did not work, but when i pause the code and inspect the bitmap and then allow the code to continue to then works???? WTF.

    I'm guessing something is being lazily loaded somewhere by WPF, but this is just a guess


    0 comments No comments

  2. Marc Jeeves 386 Reputation points

    I also tried to use a convertor but i have the same issue if i dont inspect the bitmap conversion the image is not shown if i pause the code and look at the bitmap then it shows

                                Source="{Binding SimpleNotificationImage,Converter={StaticResource StringtoBitmapImageConvertor}}"
    using System;
    using System.Globalization;
    using System.Windows.Data;
    using System.Windows.Media.Imaging;
    namespace UI_Catalog.Convertors
        public class StringtoBitmapImageConvertor : IValueConverter
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
                if (value != null)
                    string imagename = value as string;
                    BitmapImage bitmapImage = new BitmapImage(new Uri(imagename, UriKind.Relative));
                    return bitmapImage;
                return null;
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
                throw new NotImplementedException();
    0 comments No comments