0

I have a wpf application in which I have to add image resources dynamically. The respective code is as below.

public class ImageNames
    {
        static string path = @"pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/Images/";
        public static BitmapImage TickImage = new BitmapImage(new Uri(path + "icon_tick.gif", UriKind.Absolute));
        public static BitmapImage CrossImage = new BitmapImage(new Uri(path + "icon_cross.gif", UriKind.Absolute));
        public static BitmapImage DeleteImage = new BitmapImage(new Uri(path + "icon_delete.gif", UriKind.Absolute));
    }

The images are added in the respective assembly with Build Action = Resource. But an exception is thrown at runtime while creating the BitmapImage as Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.

SohamC
  • 2,367
  • 6
  • 22
  • 34
  • What does the Xaml look like that is referencing the images – Mark Hall Sep 26 '13 at 03:31
  • The image reference is in a converter...However the code worked when i tried it with Absolute address, i.e., C:/Projects/...I do not understand why the code with relative address is not functioning – SohamC Sep 26 '13 at 05:42
  • Take a look ,this may help you [http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code][1] [1]: http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code – Abhinavlovestackoverflow Sep 26 '13 at 05:54

0 Answers0