Binding of an Image in the Preject Resource

Asked

Viewed 21 times

0

Good morning, you guys.

I’m making a weather app for the course I’m doing and the weather icons we pull direct from links on the internet.

How I would do it locally?

The Icon is specified by an int Weathericon variable. I downloaded the images, and put them in the project Resource with the name referring to her number in veritable to facilitate, as it is on the site. Both over the internet and through the full path of the image I just put the variable in the path and ready: @"~\..\..\WIcon\" + Condition.WeatherIcon.ToString() + ".png"

How I could place this image that is in the project’s Source, being specified by this variable, inside a picturebox?

EDIT:

Weathervm.Cs

public Bitmap Icon
    {
        get 
        {
            ResourceManager rm = Resources.ResourceManager;
            Bitmap icone = (Bitmap)rm.GetObject(Condition.WeatherIcon.ToString() + ".png");
            return icone;
        }
        
    }

XAML

<Image DataContext="{StaticResource vm}"
       Source="{Binding Icon}"/>

1 answer

0

You can use Resource Manager:

ResourceManager rm = Resources.ResourceManager;
Bitmap icone = (Bitmap)rm.GetObject(Condition.WeatherIcon.ToString() + ".png");
  • I did this but it doesn’t appear in the designer. I edited the question by putting part of the code. What I’m doing wrong?

  • From the research I’ve done you need a BitmapImage instead of Bitmap. If you put a name in this pictureBox, you can change by code even using Bitmap?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.