I apologize for not blogging in a while. I have been focused 100% on getting a prototype of our product ready for some meetings we have across the pond at months end and haven't had a chance to get on here.
In building our application we have created a big resource dictionary that contains nothing but DrawingImage objects. I created a helper class to to give me some intellisense to get the images out of this resource dictionary. The resource dictionary is stored in its own XAML file. As we added more and more objects it became more difficult to remember exactly what the objects looked like.
I then started looking for some 3rd party Vector graphics files and found Grafile. The provided samples of their work that are already put in XAML resource dictionaries. However they provided no thumbnails to facilitate browsing the images.
This made me realize that there is definitely a need out there for a simple DrawingImage browser application. Four hours later and I had one :) Attached to this post is my source and a compiled .exe. The code is in VB but should be pretty straighforward to C# people.
The most interesting challenge when writing this code was how to load xaml files off of disk into a resource dictionary. Most examples I've seen have the XAML files in the project. The trick is to use the System.Windows.Markup.XAMLReader. This can "load" the xaml out of a stream into an object, in this case a resource dictionary object declared in code. I had already read my xaml file into a byte array (as I also keep it in an xmldocument object which I'll explain in a second) and was able to simply use a memorystream object that pointed to this bytearray and use that to load it into the XAMLReader.
Because there is no way to access the resourcedictionary by index, just by key, I also keep a copy of the resource dictionary in an xmlNodeList. This way I can get the key easily.
Another stumbling block is the lack of a directory picker in WPF. I used the system.win32.OpenFileDialog method which isn't perfect (it looks like you are picking a file) but works for now. To make it seem like this behavior is by design I made it so that when you select a file it opens the whole directory but makes the file you selected the "active file."
The application is simple to use. It lets you select a directory (or even a file in a directory) and presents a list of files with the .xaml extension in a simple listbox. If you select a file that is a resource dictionary with drawing images in it then it will load up the first drawingImage on the right side. It gives you the "key" name of the image in the resource dictionary and a slider to move from image to image.
I included a test resource dictionary in the zip file. Also, please don't use the maginfier icon that I provided in your commercial apps, it is something that I created for my commercial app and I'd like to keep it unique (its not that great anyway).
If anyone wants to play it would be cool to add a "filmstrip" type view giving previews of all images.
I already found some duplicate entries in our rather large Images ResourceDictionary thanks to this program. It is going to be very useful for us going forward and I figure I'd share it with the community!
Sean
ImageBrushViewer.zip