private XElement SerializeDesignerItems(IEnumerable<designeritem> designerItems)
{
XElement serializedItems = new XElement("DesignerItems",
from item in designerItems
let contentXaml = XamlWriter.Save(((DesignerItem)item).Content)
select new XElement("DesignerItem",
new XElement("Left", Canvas.GetLeft(item)),
new XElement("Top", Canvas.GetTop(item)),
new XElement("Width", item.Width),
new XElement("Height", item.Height),
new XElement("ID", item.ID),
new XElement("zIndex", Canvas.GetZIndex(item)),
new XElement("IsGroup", item.IsGroup),
new XElement("ParentID", item.ParentID),
new XElement("Content", contentXaml),
new XElement("Tooltip", value),
new XElement("testValuex", debugClass.commandList.Keys, debugClass.commandList.Values),
)
);
return serializedItems;
}
testValuex is a dictionary consisting of guids and certain commands
the given below is my code for deserilization
private static DesignerItem DeserializeDesignerItem(XElement itemXML, Guid id, double OffsetX, double OffsetY)
{
DesignerItem item = new DesignerItem(id);
item.Width = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture);
item.Height = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture);
item.ParentID = new Guid(itemXML.Element("ParentID").Value);
item.IsGroup = Boolean.Parse(itemXML.Element("IsGroup").Value);
Canvas.SetLeft(item, Double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + OffsetX);
Canvas.SetTop(item, Double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + OffsetY);
Canvas.SetZIndex(item, Int32.Parse(itemXML.Element("zIndex").Value));
Object content = XamlReader.Load(XmlReader.Create(new StringReader(itemXML.Element("Content").Value)));
item.Content = content;
return item;
}