/// <summary> /// /// </summary> /// <param name="canvas"></param> /// <returns></returns> public static XamlCanvasTemplate DecodeXml(XElement canvas) { if (null == canvas) { return(new XamlCanvasTemplate()); } XamlCanvasTemplate temp = canvas.ToModel <XamlCanvasTemplate>(); var rootAtt = canvas.Attributes(); foreach (var ra in rootAtt) { temp.CanvasPropertyItem.Add(ra.ToString()); temp.CanvasPropertyDict.Add(ra.Name.LocalName, ra.Value); } var childerns = canvas.Elements(); if (null != childerns && 0 < childerns.Count()) { foreach (var child in childerns) { List <string> item = new List <string>(); var attItem = child.Attributes(); foreach (var a in attItem) { item.Add(a.ToString()); } string _result = string.Format("{0} {1} />", child.ToString().Split(' ')[0], string.Join(" ", item)); string key = child.GetAttributeValue("Name"); temp.Children.Add(key, _result); } } return(temp); }
/// <summary> /// /// </summary> /// <param name="xaml"></param> /// <returns></returns> public static XamlTemplate DecodeXml(string xaml) { XamlTemplate temp = new XamlTemplate(); if (xaml.IsNullOrEmpty()) { return(temp); } XElement xe = XElement.Parse(xaml); var Attributes = xe.Attributes(); foreach (var v in Attributes) { try { if (v.Name.LocalName.Equals("Height")) { temp.Height = double.Parse(v.Value); continue; } if (v.Name.LocalName.Equals("Width")) { temp.Width = double.Parse(v.Value); continue; } } catch { } string value = v.ToString(); if (value.IsNullOrEmpty()) { continue; } if (temp.IsExists(value)) { continue; } temp.AssemblyCollection.Add(value); } var canvas = xe.FirstNode as XElement;//.Element("Canvas"); if (null != canvas) { temp.CanvasTemplate = XamlCanvasTemplate.DecodeXml(canvas); } return(temp); }