- Go to Project properties / Resources tab.
- At the tab top menu, click the down arrow to the right of Add Resource and click Add Existing File.
- Select image files on disk. The files will be displayed on resouces tab. You will also notice that a Resources folder has been created in solution explorer.
- In solution explorer, select the image files under Resources and right click, select Properties
- Change Build Action to Resource
- In your code: MyImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/" + imgFileName)
- Clean Solution, Build Solution
- Now your code will run correctly. The image files will be embedded into the exe file, you won't need to distribute the images as separate files.
Monday, September 18, 2017
Using images as resources in C# WPF
To use images as embedded resouces in C# WPF (Visual Studio 2017):
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment