将 XML 添加到我的项目中没有问题:
using System.Xml;
using System.Xml.Serialization;
public string ToXML(Object oObject)
{
XmlDocument xmlDoc = new XmlDocument();
XmlSerializer xmlSerializer = new XmlSerializer(oObject.GetType());
using (MemoryStream xmlStream = new MemoryStream())
{
xmlSerializer.Serialize(xmlStream, oObject);
xmlStream.Position = 0;
xmlDoc.Load(xmlStream);
return xmlDoc.InnerXml;
}
}
之后,可以共享 XML 字符串:
public MvxCommand ShareWaypoints => new MvxCommand(ShareWaypointsAsync);
public async void ShareWaypointsAsync()
{
try
{
string strXML = "";
foreach (var wp in waypoints)
{
strXML += ToXML(wp);
}
if (strXML != "")
await Share.RequestAsync(new ShareTextRequest
{
Text = strXML,
Title = "Share Text"
});
}
catch (Exception ex)
{
await _userDialogs.AlertAsync(ex.Message);
}
}