February 11th, 2010, 03:01 AM
Binding XML Data in a ListBox
I have this piece of code:
XmlDocument doc = new XmlDocument();
// Initially value "<ParentNode></ParentNode>"
doc = mngr.XmlDoc;
XmlDataProvider xmlDP = new XmlDataProvider();
xmlDP.Document = doc;
xmlDP.XPath = "/ParentNode/ChildNode";
CollectionViewSource collection = new CollectionViewSource();
collection.Source = xmlDP;
collection.SortDescriptions.Add(new SortDescription("ChildNodeName", ListSortDirection.Ascending);
Binding bnd = new Binding();
bnd.Source = collection;
Sample Xml Document:
When I run my application (No item in the list box), "SOMETIMES" the listbox would have a ListBoxItem which is in XmlDocument. So when I do listbox.Items.InnerXml, it would return "<ParentNode></ParentNode>".
My expectation is that it would not generate any item because the XPath specified is " /ParentNode/ChildNode" which obviously not XmlDocument in this case.
When I run my application (Atleast 1 item in the list box), the listbox would have a ListBoxItem which is in XmlNode. So when I do listbox.Items.OuterXml, it would return "<ChildNode><ChildNodeName/></ChildNode>".
This is correct.
Tags for this Thread
Click Here to Expand Forum to Full Width