我有一个包含静态ImageSource对象的类,这些对象以后经常被其他类访问:
public class ImagePrepare
{
public static readonly ImageSource m_imageGreen;
public static readonly ImageSource m_imageYellow;
public static readonly ImageSource m_imageRed;
public static readonly ImageSource m_imagePurple;
public static int iTest;
//static Constructor
static ImagePrepare()
{
iTest = 2;
Uri uriImage = new Uri("pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/" + "Ressourcen/Button_Green.png", UriKind.Absolute);
ImageSource m_imageGreen = new BitmapImage(uriImage);
uriImage = new Uri("pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/" + "Ressourcen/Button_Yellow.png", UriKind.Absolute);
ImageSource m_imageYellow = new BitmapImage(uriImage);
uriImage = new Uri("pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/" + "Ressourcen/Button_Red.png", …Run Code Online (Sandbox Code Playgroud)