There seems to be some implementations of XamlWriter for Silverlight around. The one I've seen which looks most serious is in Silverlight Contrib, but this is not yet supported for SL3, which I'm using.
Since I only had a few specific objects to extract xaml from I created the functions to do so myself. Some more refactoring will be done, but this one works for finding the xaml for my path drawing - stored as a InkPresenter:
public static string ConvertPathToXaml(InkPresenter drawObject)
{
string xmlnsString = "http://schemas.microsoft.com/client/2007";
XNamespace xmlns = xmlnsString;
var strokes = new XElement(xmlns + "StrokeCollection");
foreach (var strokeData in drawObject.Strokes)
{
var stroke = new XElement(xmlns + "Stroke",
new XElement(xmlns + "Stroke.DrawingAttributes",
new XElement(xmlns + "DrawingAttributes",
new XAttribute("Color", strokeData.DrawingAttributes.Color),
new XAttribute("OutlineColor", strokeData.DrawingAttributes.OutlineColor),
new XAttribute("Width", strokeData.DrawingAttributes.Width),
new XAttribute("Height", strokeData.DrawingAttributes.Height))));
var points = new XElement(xmlns + "Stroke.StylusPoints");
foreach (var pointData in strokeData.StylusPoints)
{
var point = new XElement(xmlns + "StylusPoint",
new XAttribute("X", pointData.X),
new XAttribute("Y", pointData.Y));
points.Add(point);
}
stroke.Add(points);
strokes.Add(stroke);
}
var strokesRoot = new XElement(xmlns + "InkPresenter.Strokes", strokes);
var inkRoot = new XElement(xmlns + "InkPresenter", new XAttribute("xmlns", xmlnsString),
new XAttribute("Opacity", drawObject.Opacity), strokesRoot);
return inkRoot.ToString();
}