Skip to content

Instantly share code, notes, and snippets.

@bc3tech
Last active October 5, 2015 16:18
Show Gist options
  • Save bc3tech/08e4256079015f7bcc65 to your computer and use it in GitHub Desktop.
Save bc3tech/08e4256079015f7bcc65 to your computer and use it in GitHub Desktop.
Combine multiple notification XMLs in to one payload for pinned tiles
using DomXmlDocument = Windows.Data.Xml.Dom.XmlDocument;
private static DomXmlDocument CombineNotifications(List<XDocument> notificationXmlsToReturn)
{
// Per https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868253.aspx#include_both_a_square_and_wide_notification_in_the_payload
// Make the 'binding' elements in each siblings in the new one
var notificationXmlDocument = notificationXmlsToReturn.FirstOrDefault()?.ToDomXmlDocument();
if (notificationXmlDocument != null)
{
var visualTag = notificationXmlDocument.GetElementsByTagName("visual").SingleOrDefault();
if (visualTag != null)
{
foreach (var otherXmls in notificationXmlsToReturn.Skip(1).Select(n => n.ToDomXmlDocument()))
{
var nodeToAdd = notificationXmlDocument.ImportNode(
otherXmls.GetElementsByTagName("binding").Single(), true);
visualTag.AppendChild(nodeToAdd);
}
}
}
return notificationXmlDocument;
}
public static DomXmlDocument ToDomXmlDocument(this XDocument xDocument)
{
var xmlDocument = new DomXmlDocument();
xmlDocument.LoadXml(xDocument.ToString());
return xmlDocument;
}
public static XDocument ToXDocument(this DomXmlDocument xmlDocument)
{
using (var memStream = new MemoryStream())
{
using (var w = XmlWriter.Create(memStream))
{
w.WriteRaw(xmlDocument.GetXml());
}
memStream.Seek(0, SeekOrigin.Begin);
using (var r = XmlReader.Create(memStream))
{
return XDocument.Load(r);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment