So, I’ve been sitting here for a couple of hours trying to figure out why the following XML query didn’t actually work when parsing my XAML for the following item:
The XAML loaded into an XML document just fine. It’s well formed, and the Image item does exist inside the Application.Resources section. I just couldn’t figure out what the heck was going on. Then, it hit me – in a flash of the blinding, bleeding obvious. These tags don’t actually exist on their own. They are part of the XAML namespaces, which opens up a whole new line of things you need to do. Basically, in order to perform this query, I needed to import the same XAML namespaces into my XML document – and then I should be good to go. Right?
Well, not quite. The above query also needs to change slightly. Without, the namespaces in, this query still doesn’t work. So the first thing we need to do is add the namespaces into the query and we get:
and the code to load the namespaces in:
private static XmlNamespaceManager GetNamespace(XmlDocument doc)
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);