无法添加WPF图像资源

时间:2013-09-26 03:22:25

标签: c# wpf image

我有一个wpf应用程序,我必须动态添加图像资源。各自的代码如下。

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));
    }

使用Build Action = Resource将图像添加到相应的程序集中。但是在创建BitmapImage为Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.

时,会在运行时抛出异常

0 个答案:

没有答案