22

I want to show an image from a file using an wpf image control. The image file resides in the application directory.

<Image Stretch="Fill" Source="dashboard.jpg" />

The file dashboard.jpg should be replaceable during or after deployment. How do I have to add the image to the project and what BuildAction do I have to use to have the image read from the file system rather than any source I cannot change after deployment. What source uri do I have to use?

PVitt
  • 11,500
  • 5
  • 51
  • 85

2 Answers2

35
ImageSource imageSource = new BitmapImage(new Uri("C:\\FileName.gif"));    
image1.Source = imageSource;
Rudresh Bhatt
  • 1,935
  • 2
  • 23
  • 29
24

In markup:

<Image Stretch="Fill">
    <Image.Source>
        <BitmapImage UriSource="dashboard.jpg"/>
    </Image.Source>
</Image>
battey
  • 458
  • 4
  • 13