0

我有一个 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.

4

0 回答 0