Setting an image.Source from a resource file

14,320

set source to new BitmapImage(new Uri("C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png")) You can set in XAML to string value, because registered converter is used under the hood;

Share:
14,320
Sergio Tapia
Author by

Sergio Tapia

I'm a 21 year old professional programmer that likes to read about a wide range of things related to programming. Currently, I'm pounding away at ASP.Net MVC2.

Updated on June 27, 2022

Comments

  • Sergio Tapia
    Sergio Tapia almost 2 years
    private void SetCredentials()
    {
        username = txtfromEmail.Text;
        password = txtpassword.Text;
    
        pictureLogin.Source = @"C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png";
    }
    

    I get an error: "Cannot convert string to ImageSource".

    What can I do?

  • Sergio Tapia
    Sergio Tapia about 14 years
    And if I want to use the "/ok.png" form instead of the long string, how can I do that?
  • Yuriy Zanichkovskyy
    Yuriy Zanichkovskyy about 14 years
    just creating Uri object, and specifying UriKind.Relative