0

I try to change picture of image1. In collection I have "1.png" and "2.png".

In properties of image1 the Source is "/Appname;component/pictures/1.png"

I wrote:

image1.Source = "/Appname;component/pictures/2.png";

but it doesn't work, of course, because "implicit conversion from string to System.Windows.Media.ImageSource is not possible".

How to change the picture in image1 to "2.png"?

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
Alexander V.
  • 1,573
  • 3
  • 10
  • 12
  • 1
    Have you looked at this question and answer - http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code ? – Zann Anderson Nov 09 '11 at 17:21

1 Answers1

1

You cannot directly assign a string as image source. But you can use a BitmapImage as source.

Example:

BitmapImage bitmap = new BitmapImage(new Uri("/Appname;component/pictures/2.png", UriKind.Relative));
image1.Source = bitmap;

If this doesn't work then something is wrong with your Uri (image path) and you should have a look at the link provided by Zannjaminderson (in the comments).

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85