string serializeLayer(GraphicsLayer layer) { Dictionary <string, string> Namespaces = new Dictionary <string, string>(); Namespaces.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriNamespace); Namespaces.Add("esriBing", "clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing"); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriMappingPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriMappingNamespace); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriFSSymbolsPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriFSSymbolsNamespace); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriExtensibilityPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriExtensibilityNamespace); StringBuilder xaml = new StringBuilder(); XmlWriter writer = XmlWriter.Create(xaml, new XmlWriterSettings() { OmitXmlDeclaration = true }); writer.WriteStartElement("ContentControl"); // write namespaces foreach (string key in Namespaces.Keys) { string _namespace = "http://schemas.microsoft.com/winfx/2006/xaml"; // default if (Namespaces.ContainsKey(key)) { _namespace = Namespaces[key]; } writer.WriteAttributeString("xmlns", key, null, _namespace); } ESRI.ArcGIS.Mapping.Core.GraphicsLayerXamlWriter layerWriter = new Core.GraphicsLayerXamlWriter(writer, Namespaces); layerWriter.WriteLayer(layer, layer.GetType().Name, ESRI.ArcGIS.Mapping.Core.Constants.esriNamespace); writer.WriteEndElement(); writer.Flush(); writer = null; string config = xaml.ToString(); // Inject default namespace config = config.Insert(16, "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" "); return(config); }
string serializeLayer(GraphicsLayer layer) { Dictionary<string, string> Namespaces = new Dictionary<string, string>(); Namespaces.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriNamespace); Namespaces.Add("esriBing", "clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing"); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriMappingPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriMappingNamespace); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriFSSymbolsPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriFSSymbolsNamespace); Namespaces.Add(ESRI.ArcGIS.Mapping.Core.Constants.esriExtensibilityPrefix, ESRI.ArcGIS.Mapping.Core.Constants.esriExtensibilityNamespace); StringBuilder xaml = new StringBuilder(); XmlWriter writer = XmlWriter.Create(xaml, new XmlWriterSettings() { OmitXmlDeclaration = true }); writer.WriteStartElement("ContentControl"); // write namespaces foreach (string key in Namespaces.Keys) { string _namespace = "http://schemas.microsoft.com/winfx/2006/xaml"; // default if (Namespaces.ContainsKey(key)) _namespace = Namespaces[key]; writer.WriteAttributeString("xmlns", key, null, _namespace); } ESRI.ArcGIS.Mapping.Core.GraphicsLayerXamlWriter layerWriter = new Core.GraphicsLayerXamlWriter(writer, Namespaces); layerWriter.WriteLayer(layer, layer.GetType().Name, ESRI.ArcGIS.Mapping.Core.Constants.esriNamespace); writer.WriteEndElement(); writer.Flush(); writer = null; string config = xaml.ToString(); // Inject default namespace config = config.Insert(16, "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" "); return config; }