For one of our current projects I needed to convert some hazard symbols from SVG to XAML to use them in a Silverlight GIS front-end. After querying the web I found several tools that supposedly do so. However none of them fitted my needs.
- A few of them where payable products; and they only offered severely crippled demo versions
- One of them was a plugin for Adobe Illustrator, and I do not have it :)
- Inkscape has an export to xaml function (Save As -> Microsoft XAML), but trying that on the hazard symbols mentioned above (you can download the SVG’s following that link) turned out to be no good. While the xaml could be parsed correctly from a technical view point, it rendered images that where nothing like the original SVG’s
One of the search results mentioned the Microsoft XPS Document Writer printer driver. And to my suprise, you can in fact use that one in the process of converting SVG’s to XAML :)
Here’s what I did:
This may seem a bit tedious, but in fact works quite well once you have done a few conversions :)
First, you need an SVG file. For example: this one
Secondly, you need to open that SVG file in Inkscape (I have had no luck printing the SVG from my browser, probably because it uses some weird plugin to render the SVG).
Then print the SVG from within Inkscape to the Microsoft XPS Document Writer. You have to specify a file name:
Then go to the location of the .xps file and rename its extension to .zip (yep, apparently it is also a zip file :))
Browse the zip file for \Documents\1\Pages\1.fpage and extract that file.
Optionally rename its .fpage extension to .xml to open it up in your favourite xml editor. Alternatively leave the file as-is and open it in any text editor (notepad will do).
You should see something like:
<FixedPage Width="816" Height="1056" xmlns="http://schemas.microsoft.com/xps/2005/06" xml:lang="und"> <Path Data="F0 M 4.32,528.8 L 528.8,528.8 528.8,4.32 4.32,4.32 4.32,528.8 z" Fill="#ffff7d00" /> ... snip ... </FixedPage>
If you copy-paste all the lines that are enclosed between the <FixedPage> tags inside a <Canvas> tag you have fully functional XAML ready to be used in your Silverlight or WPF application :)