I've attached C# code allowing XML serialization/deserialization of Graphics. It's developed as an extension of GraphicsLayer: So, in WPF, you can serialize to a file with code like:
string dataFile = @"graphics.xml";
using (XmlWriter writer = XmlWriter.Create(dataFile, new XmlWriterSettings() { Indent = true }))
{
myGraphicsLayer.SerializeGraphics(writer);
writer.Close();
}
and deserialize with :
myGraphicsLayer.ClearGraphics();
using (XmlReader reader = XmlReader.Create(dataFile))
{
myGraphicsLayer.DeserializeGraphics(reader);
reader.Close();
}
The generated XML looks like:
<?xml version="1.0" encoding="utf-8"?>
<Graphics xmlns:sys="http://www.w3.org/2001/XMLSchema" xmlns:esri="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry" xmlns:col="http://schemas.datacontract.org/2004/07/System.Collections.Generic" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Samples">
<Graphic>
<Attributes>
<Attribute>
<col:key>OBJECTID</col:key>
<col:value i:type="sys:int">1</col:value>
</Attribute>
<Attribute>
<col:key>Name</col:key>
<col:value i:type="sys:string">Graphic1</col:value>
</Attribute>
</Attributes>
<Geometry i:type="esri:Polygon">
<esri:spatialReference>
<esri:wkid>4326</esri:wkid>
</esri:spatialReference>
<esri:rings>
<esri:points>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>120.039</esri:x>
<esri:y>-20.303</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>142.539</esri:x>
<esri:y>-7.0137</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>163.281</esri:x>
<esri:y>-13.923</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>172.773</esri:x>
<esri:y>-35.174</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>173.594</esri:x>
<esri:y>-43.18</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>121.797</esri:x>
<esri:y>-36.032</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>120.039</esri:x>
<esri:y>-20.303</esri:y>
</esri:point>
</esri:points>
</esri:rings>
</Geometry>
</Graphic>
<Graphic>
<Attributes>
<Attribute>
<col:key>OBJECTID</col:key>
<col:value i:type="sys:int">2</col:value>
</Attribute>
<Attribute>
<col:key>Name</col:key>
<col:value i:type="sys:string">Graphic2</col:value>
</Attribute>
</Attributes>
<Geometry i:type="esri:Polygon">
<esri:spatialReference i:nil="true" />
<esri:rings>
<esri:points>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>130.039</esri:x>
<esri:y>-20.303</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>152.539</esri:x>
<esri:y>-7.0137</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>173.281</esri:x>
<esri:y>-13.923</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>179.773</esri:x>
<esri:y>-35.174</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>179.594</esri:x>
<esri:y>-43.18</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>131.797</esri:x>
<esri:y>-36.032</esri:y>
</esri:point>
<esri:point>
<esri:spatialReference i:nil="true" />
<esri:x>130.039</esri:x>
<esri:y>-20.303</esri:y>
</esri:point>
</esri:points>
</esri:rings>
</Geometry>
</Graphic>
</Graphics>
You can also use it with other kind of stream. Example in silverlight with IsolatedStorage:
string dataFile = @"graphics.xml";
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = store.CreateFile(dataFile))
{
using (XmlWriter writer = XmlWriter.Create(fileStream, new XmlWriterSettings() { Indent = true }))
{
graphicsLayer.SerializeGraphics(writer);
writer.Close();
}
fileStream.Close();
}�??
Note that the symbol is not serialized, so it's only working if there is a renderer associted to your layer or if you reset the symbols by code after the deserialization (else the grahics end up wihout any symbol and so are not rendered.