views:

2586

answers:

5
+8  Q: 

XAML to SVG?

How would you go about converting XAML to SVG and vice versa?

My initial approach it to use xslt to map the different elements and attributes, but I don't know enough about both syntaxes to even guess about the plausibility of such an approach.

A: 

I'm not sure if you quite understand the differences between XAML and SVG.

XAML is a language used to describe how a GUI will look under WinFX. SVG is a language used to describe how a vector image will look.

Neither of these are interchangeable.

GateKiller
XAML is serialized object graphs. You can serialize any .NET object to XAML. Don't forget, WF workflows are serialized to XAML. I find it a whole lot better than using XML to serialize objects.
Will
A: 

Here'a a link to XSL's which help you do this: http://members.chello.nl/~a.degreef/XAML.html

There are tools out there as well which do this.

Vaibhav
+2  A: 

You can convert SVG to XAML, as WPF has plenty of vector graphics goodness. There are plenty of tools and plugins you can use to convert one to another.

While I think any SVG graphics can be converted to XAML, not all XAML can be converted to SVG.

Really, any object graph can (with some small limitations) be serialized to XAML, so it only makes sense that that "all" XAML can't be converted back.

Check out www.wpf-graphics.com as a starting point for converters, and don't forget google.

Will
+9  A: 

XAML is a superset of SVG, since it's an entire application description language. While SVG has some basic programmability functions (enough to build a Tetris game, for example), it's really a vector graphic format.

Some options:

Jon Galloway
XAML's features may be a superset of SVG's, but the XAML isn't itself a superset of SVG the way C++ or Objective-C is a superset of C or HTML-Framset is a superset of HTML-Strict.
David Leppik
XamlTune is very nice, even if it seems not updated anymore
marco.ragogna
+1  A: 

As none of the above could fulfill my needs, I developed a set of conversion tools on my site

I have put some info about them on my site in the form of a library, online tool, usercontrol and batch app; an svgviewer for wpf will follow shortly.

Some of the points I tried to address (that I found more or less lacking in some of the existing tools):

  • Text as TextBlocks instead of Paths
  • Callability from free-threaded (or non-STA) code (web apps, web services, parallel batch conversions, etc...) (cf. w3c's basic tutorials/examples)
  • Correct measurement for stuff like width="100%" (for the top-level canvas, for instance)
  • Consideration for GraphViz generated svg files

You can try this version online; I am happy to implement any feature requests as long as they fit my priorities and schedule.

ps: Working on the Silverlight versions

Ciper