StackPanel

dynamic rants = new Stack();

Jul
08

xmlns in Xml data islands

Posted under Software development by Vin

You have an xml that you want to load up in a WPF treeview, use HierarchicalDataTemplate, the Xml coming from an Xml data island of a XmlDataProvider. But after hours of trying different XPath expressions, other samples and gravity defying stunts the Treeview doesn’t load up the Xml tree data. Why?

Answer: The root element of the Xml data island should have an xmlns attribute empty.


Note from MSDN

The root node of the XML data has an xmlns attribute that sets the XML namespace to an empty string. This is a requirement for applying XPath queries to a data island that is inline within the XAML page. In this inline case, the XAML, and thus the data island, inherits the System.Windows namespace. Because of this, you need to set the namespace blank to keep XPath queries from being qualified by the System.Windows namespace, which would misdirect the queries.

Example:


Here’s the msdn link(look under Note section)

Add A Comment