Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an image.Source from a resource file

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?

like image 242
Sergio Tapia Avatar asked Jan 29 '10 15:01

Sergio Tapia


People also ask

How do I add an image to a resource?

Create a new resource, say, Images. resx in in some directory. Have some ready to use JPEG file. Open the created resource and use "Add Resource" -> "Add Existing File", add your file.

How do you change the source of an image in UWP?

Here's how to set the source to an image from the app package. Image img = new Image(); BitmapImage bitmapImage = new BitmapImage(); Uri uri = new Uri("ms-appx:///Assets/Logo.png"); bitmapImage. UriSource = uri; img. Source = bitmapImage; // OR Image img = new Image(); img.


1 Answers

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;

like image 197
Yuriy Zanichkovskyy Avatar answered Oct 30 '22 15:10

Yuriy Zanichkovskyy