tags:

views:

91

answers:

0

Hi there,

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;

listbox.SetBinding(ListBox.ItemsSourceProperty, bnd);

Sample Xml Document:

-- Case 1: 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[0].InnerXml, it would return "".

My expectation is that it would not generate any item because the XPath specified is " /ParentNode/ChildNode" which obviously not XmlDocument in this case.

Case 2: 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[0].OuterXml, it would return "".

This is correct.

Please help.