0

I have a wpf app with an image in the xaml:

<Image HorizontalAlignment="Center" Height="131" Margin="550,0,1306,-960" VerticalAlignment="Bottom" Width="58" Source="../images/blue.JPG" Name="im_Izq"/>

And I want to change the source image from the code behind. I tried the following:

im_Izq.Source = new BitmapImage(new Uri("../../images/red.JPG"));

but, when running it, I get this error:

System.UriFormatException: 'URI no válido: no se puede determinar el formato del URI.'

Can you help me? Thanks!!

Raulus
  • 95
  • 2
  • 10

1 Answers1

0

Make sure the image file is located in a project folder named images, and set the Build Action of the file to Resource.

im_Izq.Source = new BitmapImage(new Uri("pack://application:,,,/images/red.JPG"));

or use

im_Izq.Source = new BitmapImage(new Uri(@"/projectname;component/Images/up.ico", UriKind.Relative));
Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17