4

I have started using xaml based icons in my WPF app, but am struggling to find a simple way to store and share them. The icons are DrawingBrushes.

Do I?

A) Store each icon in its own xaml file wrapped in a resource dictionary. This means that I either have to pull in each icon resource every time I want to paint one, or create a standard "icons" dictionary that pulls every xaml file. This seems a pain to have to maintain, and I still have to pull in the icons resource dictionary every time I want to use an icon.

If I did go for this, how do people normally display the icon? Just a Canvas with the brush as the background?

B) Store each icon in its own xaml file as a UserControl. This makes displaying an icon dead easy - just plonk the approprate control in, and its arguably simpler to declare the XML icons namespace at the top of your XAML rather than merging a resource dictionary.

C) Store all icons in one XAML file wrapped in a resource dictionary. One dictionary to merge but without the maintenance of pulling in individual files into that dictionary. Potentially awkward to edit icons though.

D) ....?

How are other people managing their icons?

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
  • why do you have to use `DrawingBrush` to display each icon? – Jake Berger Feb 17 '12 at 15:06
  • Possibly I don't. Just thought a brush would be less resource intensive. What would you suggest? – GazTheDestroyer Feb 17 '12 at 15:18
  • you could try adding the .ico files with `Build Action` = `Resource`. i've heard (can't remember off the top of my head) that there is a certain more efficient way to store images which are used often. Could be: `BitmapImage`, `BitmapSource`, `ImageSource`..? Check out [`System.Windows.Media`](http://msdn.microsoft.com/en-us/library/system.windows.media.aspx) and [`System.Windows.Media.Imaging`](http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.aspx) – Jake Berger Feb 17 '12 at 16:41
  • We use option A. Can't say if it's 'the standard way' or not though. – Phil Feb 17 '12 at 17:42
  • @Phil: useful to know though thanks. Do you pull in each icon as you need it or do you have a dictionary with them all in? – GazTheDestroyer Feb 17 '12 at 17:50
  • Thinking about it we have two schemes. 1) We have related icons as ... in resource dictionaries, 2) for dynamically loaded components that have a root view and an associated icon the icon is stored in its own file as a ... – Phil Feb 17 '12 at 17:56
  • I think your solution is in this article. [http://stackoverflow.com/questions/8836935/how-to-reuse-icons-xaml-paths-in-a-large-project][1] [1]: http://stackoverflow.com/questions/8836935/how-to-reuse-icons-xaml-paths-in-a-large-project – visionarycoder Jul 20 '12 at 23:38

0 Answers0