XDraw 2.0: Handling single drawing .xaml files

Aug 4, 2010 at 5:00 AM

In order to simplify organization and reuse of .xaml based icons in an application I work on, myself and a few other developers have generally begun to put each icon (generally a DrawingBrush or DrawingImage) in separate .xaml resource dictionary files. Whether this is advisable or otherwise a good idea in the long term is another topic however I think it may be useful to deal with single drawings in this fashion for the sake of simplifying basic usage of XDraw.

To see why this would be useful lets take a look at a few usage scenarios.

A Graphics Designer

User A has a graphics design background and is curious about XAML and WPF but is generally a non-programmer and is also on a limited budget leaving XDraw as an application of interest to explore drawing in XAML. In order to use XDraw to make a basic drawing User A would like to follow the steps below.

  1. Install the application (perhapse through downloadable .msi or setup.exe but preferably a ClickOnce installation)
  2. Launch the application (note: this is automatically done by default for ClickOnce applications)
  3. Be presented with a fresh drawing surface, preferably with no additional actions
  4. Explore through usage the drawing tools available to create a single workable drawing
  5. Save the drawing to disk for later editing
  6. Reopen the editing session by either locating the file and opening it through Windows Explorer or by relaunching the application manually and opening the previously saved drawing

XDraw already has the basics down and offers a relatively clean and productive environment once the a drawing is prepared however the work involved in setting up a new drawing and opening one are made too cumbersome due to the necessity of a project file and a resource dictionary .xaml file to manage it's related drawings. Also users such as User A may be turned off by the fact that certain niceties such as presenting a default drawing when the application is opened, prompting the user to save unsaved changes when closing a drawing, and associating .xaml files in some way within Windows for reopening resource dictionaries within XDraw.


A WPF Application Developer

User B is a C# developer who is required to provide basic User Interface implementations as part of their job. Part of User B's work involves creating simple icons and/or other visual primitives to use within a WPF application. Tools exist for User B to produce XAML based vector drawings such as Expression Design, or Inscape but these tools are either costly or combersome when used for this purpose and do not allow for cyclical editing (once exported to XAML that resulting XAML drawing can no longer be edited within that tool). Use B would rather follow the usage pattern detailed below.

  1. Identify an existing drawing within a Visual Studio solution that is to be edited
  2. Launch XDraw to edit the specified drawing
  3. Use XDraws drawing tools to modify the existing drawing
  4. Save any changes back to the original file
  5. Close XDraw and return to Visual Studio in order to hand manipulate the drawing or do other work

As of right now this type of task could be achieved a few different ways but all of which require many more steps than the ones listed above. One example way to achieve this with the current version of XDraw (1.2) would be to follow the steps layed out below.

  1. Identify a drawing within code
  2. Copying the drawing into the clipboard
  3. Launching XDraw
  4. Creating a new project
  5. Creating a new drawing within the project
  6. Importing the drawing from the clipboard
  7. Modifying the drawing
  8. Saving the project and drawing
  9. Locating the saved resource dictionary file on disk
  10. opening the resource dictionary file within a text editor such as notepad
  11. copying the section containing the DrawingImage or Canvas
  12. Closing the text editor
  13. Returning to visual studio
  14. Pasting the copied Drawing in XAML from from clipboard to overwrite the original drawing

To get closer to the shorted set of steps outlined initially up above we could do three main things.

Firstly handling a resource dictionary file on it's own within XDraw would solve a lot of the problems even if it were to only understand resource dictionaries that contain only a single drawing. If a resource dictionary file could be specified as a command line argument to XDraw when it is opened then it would be even easier to open .xaml files from the command line, Windows Explorer, or even Visual Studio through the Open With feature.

Secondly the ability to unobtrusively persist changes to a drawing within a resource dictionary without modifying any other elements would be a great benefit. With this capability a resource dictionary file containing a drawing could be both opened, modified, and then saved without any extra steps of copying data to the clipboard, creating and deleting temporary files, or involving use of any other applications such as notepad.

Thirdly anything done to integrate XDraw into Visual Studio or other development platforms would greatly improve the overall experience. With the first two improvements listed a developer would at least be able to set up XDraw to handle resource dictionary files through Visual Studio through the Open With menu option or through Windows Explorer if .xaml files are associated to XDraw but having a Visual Studio Add-in that adds a Edit in XDraw context menu item to any DrawingImage or perhaps a Canvas element within the XAML editor when either of these elements is right clicked would just be awesome. Adding a similar extension to the Windows Shell so that an a similar item appears in the context menu within Windows Explorer would also be helpful. And all of this would still be very useful and not too dificult to implement even if there was a single DrawingImage per .xaml file restriction imposed by XDraw although being able to do the same thing with any old resource dictionary file regardless of it's contents should still be possible and would be even better or at least that's what I've heard from User B... cough cough.


Overall I think XDraw shows great potential once some of the kinks are worked out especially since Microsoft has left a void in functionality with managing XAML based vector drawing assets that XDraw may be able to fill. Let me know what you think about whether you think the suggestions above make sense or not. I would be willing to help contribute as a developer for this project as well if time permits so I'm interested in any feedback from users and or the Project Coordinator.

Aug 5, 2010 at 7:40 AM

I agree with all of this mainly.

As already mentioned in the other thread: Time is the resource which is missing here.

Most of your topics came in my mind as well, plus some additional like:

  • Save the files in my own format, and create xaml with single file generator (a VS feature) (might be a bad Idea, not sure so far)
  • Put additional informations directly in xaml file as comments to get rid of the xdraw project file (might be the better idea, if noone mess around with the comments)
  • and manny more...

One problem about all of this is, that some of the xdraw code internals are quite messy and needs a redesign. It started as a 'I want some canvas drag&drop action' playground.

As soon as I find some time I will get on it, and if I find a way to 'modulize' it, I will come back to you to ask for assistance.


Aug 6, 2010 at 5:39 AM


It's funny you mentioned adding the extra information as comments to the XAML file because was thinking of including that as another suggestion.

Another alternative would be to generate a temporary project with default values for resource dictionary files that are opened directly within XDraw. Since I believe most of these values are not that important for persisting in cases where XDraw is being used just to directly modify a drawing within a resource dictionary there is probably no harm in just throwing away these values after the drawing is closed. The reasonable size for the drawing area could probably be figured out from the drawing itself assuming that it exists.

About using your own format and a single file generator, I can say that I've gone that route trying to design a custom report file format in the past and can be quite a pain. In my case I needed to generate more than one output file so I ended up abandoning the SingleFileGenerator concept and made a full fledge Add-in for Visual Studio. In the long run I ended up abandoning that approach as well because it was more of a pain to get each developer to install the add-in and also to update the add-in every time there was an update. If you are interested in creating some type of code generator or file format converter it seems that the whole T4 templates thing has gained more attention lately and is supposed to be integrated well within Visual Studio 2010 however I haven't played around with it much since Visual Studio 2008. For what it's worth, I don't think creating a custom file format would be worth the effort but I could be wrong.

I also just wanted to thank you for responding so quickly and thoroughly to my post. I look forward to what XDraw can become.


Aug 7, 2010 at 8:12 AM


After thinking a bit about everthing you wrote I came to the decission to start this project over.

I've started a thread about all of this:  [discussion:222792]