Silverlight XamlWriter
我发现.Net XamlWriter在Silverlight中不可用。好吧,反正我需要一个,所以我想有一个解决办法Silverlight XamlWriter,silverlight,xaml,Silverlight,Xaml,我发现.Net XamlWriter在Silverlight中不可用。好吧,反正我需要一个,所以我想有一个解决办法 我有一些UIElement对象(路径、椭圆、矩形等等),我想存储它们的Xaml定义,以便以后可以使用XamlWriter.load()加载它们。有什么办法吗?是否有推荐的第三方XamlWriter实现等 对于Silverlight,似乎有一些XamlWriter的实现。我所看到的看起来最严重的是Silverlight Contrib,但我正在使用的SL3还不支持它 因为我只有几个特
我有一些UIElement对象(路径、椭圆、矩形等等),我想存储它们的Xaml定义,以便以后可以使用XamlWriter.load()加载它们。有什么办法吗?是否有推荐的第三方XamlWriter实现等 对于Silverlight,似乎有一些XamlWriter的实现。我所看到的看起来最严重的是Silverlight Contrib,但我正在使用的SL3还不支持它 因为我只有几个特定的对象可以从中提取xaml,所以我自己创建了相应的函数。还将进行一些重构,但这一次可以用于查找路径图的xaml—存储为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();
}