Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the recommended way to store images used as icons for a WPF application?

I am creating a pretty standard business application in WPF. I need to use icons for the toolbars and menu items, and in a few other places. I'd like to know the answers to three (likely interrelated) things:

  • What format should I use for the images? ICO? PNG? JPG? GIF?
  • How do I store the images in my VS2008 project? As files on disk? In a RESX file? In a resource dictionary? (If in a resource dictionary, do they then also have to be on disk before the dictionary is "compiled"?)
  • Once the files are stored appropriately in my project, how best to reference them?

Thanks!

Update:

I accepted Chris Nicol's answer, but I want to clarify what I did for the record.

  1. I created a folder in my project called Images.
  2. I put my images into this folder, and made sure that their build action was "Resource".
  3. I created a ResourceDictionary XAML file called Images.xaml. Inside of this, I created an entry for each file, in the following format: BitmapImage x:Key="FooIcon" Source="Images\foo.png".
  4. I then referenced this ResourceDictionary in the usual way as needed.

My primary concern was that the resulting images be added to the DLL as resources and that they be accessible through WPF's Resource system.

like image 432
Gregory Higley Avatar asked Jun 29 '09 18:06

Gregory Higley


People also ask

How do I change the icon in WPF?

"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon."

Is Visual Studio a WPF application?

Windows Presentation Foundation (WPF) in Visual Studio provides developers with a unified programming model for building line-of-business desktop applications on Windows.


1 Answers

  1. Format - I would say .PNG from experience, though .ICO may suit your needs depending on the source and size of your original graphic.

  2. Storage - They would be resources in the project, most likely created under a folder structure. They can then be accessed through the XAML.

  3. Referencing - It depends on the architecture of your application. In the most basic solution you would have a style that would set the image source property of your toolbar (implementation depends on your control). Each toolbar would implement a style resource.

Hope that helps!

like image 131
Chris Nicol Avatar answered Nov 08 '22 14:11

Chris Nicol