An image is not loaded in BitmapImage

0

I am trying to load images at run time and each one is selected by means of a switch:

seguimiento.tareaA = new Image();
switch (rowTarea["idTareaTipo"].ToString())
                    {
                        case "f7f91a6f-24a2-1034-b505-d1f8671a4f3f"://Seguimiento
                            Uri uri = new Uri("pack://application:,,,/Resources/Seguim_Chico__0000_6_Pago_Rojo.png");
                            BitmapImage bmp = new BitmapImage(uri);
                            seguimiento.tareaA.Source = bmp;
                            break;

At the moment of running the program, it does not give errors but neither the images are loaded ... I tried to debug and the only strange thing I found was an error in the Metadata when creating the BitmapImage:

How can I solve the error or make the image show?

    
asked by German AT 26.05.2017 в 21:09
source

2 answers

1

At some point I had this problem and found a post on the original SO

The trick is to put the origin between the methods BeginInit() and EndInit()

BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/AssemblyName;component/Resources/logo.png");
logo.EndInit();

The explanation is in the official documentation :

  

Initialization of the property must take place between calls   BeginInit and EndInit. Once BitmapImage has been initialized, the   Property changes are ignored.

    
answered by 26.05.2017 / 21:58
source
0

Try this:

seguimiento.tareaA = new Image();
switch (rowTarea["idTareaTipo"].ToString())
{
    case "f7f91a6f-24a2-1034-b505-d1f8671a4f3f"://Seguimiento
    BitmapImage bi3 = new BitmapImage();
    bi3.BeginInit();
    bi3.UriSource = new Uri("pack://application:,,,/Resources/Seguim_Chico__0000_6_Pago_Rojo.png");
    bi3.EndInit();
    seguimiento.tareaA.Source = bi3;
    break;
    
answered by 28.05.2017 в 00:49