Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference image resources in XAML?

Tags:

wpf

I put an Image control on a Window and I would like to display an image that is stored in a project resource file named "Resources.resx". The name of the image in the resource file is 'Search'.

Could someone show me how I might go about doing this?

like image 227
Hosea146 Avatar asked Apr 05 '11 13:04

Hosea146


People also ask

How to set image source in wpf XAML?

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

If the image is in your resources folder and its build action is set to Resource. You can reference the image in XAML as follows:

"pack://application:,,,/Resources/Search.png" 

Assuming you do not have any folder structure under the Resources folder and it is an application. For example I use:

ImageSource="pack://application:,,,/Resources/RibbonImages/CloseButton.png" 

when I have a folder named RibbonImages under Resources folder.

like image 88
Viv Avatar answered Sep 26 '22 00:09

Viv