Skip to content

How to convert anything to XAML

Ok, so when you’re working with WPF or Silverlight, all the graphics and/or interface elements are in XAML format (or should be, for getting the most out of these technologies).

Currently, Expression Design imports formats such as *.ai (Adobe Illustrator) and export it to XAML. Other graphic editing programs, both 2D and 3D have plugins for exporting to XAML. ZAM3D actually converts most 3D formats to XAML. There is actually a converter that exports XAML from SWF (yeah).

This post isn’t about these, it’s about XPS. The XML Paper Specification (XPS) is a standard for documents from Microsoft (kind of like PDF) that can be very useful for a WPF/Silverlight programmer. Let’s see how you can convert Word to XAML, Excel to XAML (don’t know why, but you never know) or Powerpoint to XAML.

I started PowerPoint and doodled something like in the image

Then, File->Save as-> PDF or XPS. If you don’t have the addon for this, you can download it from here. Only for genuine Office products. Chose XPS from the drop down, and then go to the file location.

Now, for the fun part. Change the xps extension to zip (sounds familiar?) and then unzip the archive. Now, in the folder where the archive was unpacked, you can see a document structure. In the path Documents\1\Pages, you can see an *.fpage file. Open it up.

It’s XAML. You can import it into every project that needs XAML. For example:

But as you can see, the XAML must be fine tuned by eliminating the root element that’s not supported by WPF (nor Silverlight).

But the title of this post is Hot to convert anything to XAML. What’s the catch? The catch is Microsoft XPS Document Writer which can be found in any program when trying to print something.

So, if there’s anything you want to be in XAML format, you can try to “print” (actually create) a XPS document with that contents, and check out the archive for the XAML. Well, the export isn’t always what you’d expect (the names of the elements are all generated, a lot of resources to add to the project, expected XAML paths are often images, etc.) but in most cases it surely beats creating the whole stuff from scratch using a XAML editor.

Cheers.

4 Comments

  1. john wrote:

    Bine ai revenit .

    Posted on 29-Jun-08 at 9:02 am | Permalink
  2. Andrei wrote:

    Mersi, Ionuţ

    Posted on 30-Jun-08 at 9:24 am | Permalink
  3. vineeth wrote:

    Hello

    iam using wpf application how can we convert the xaml file to svg

    or is it any way to save canvas as svg

    give a reply urgent

    Posted on 17-Oct-08 at 12:23 pm | Permalink
  4. Andrei wrote:

    “give a reply urgent”

    Is that some sort of “plz send the teh codez”?

    http://members.chello.nl/~a.degreef/xaml/xaml2svg.xsl

    Posted on 18-Oct-08 at 11:36 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*