-
February 11th, 2010, 04:01 AM
#1
Binding XML Data in a ListBox
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:
<ParentNode>
</ParentNode>
--
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 "<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.
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 "<ChildNode><ChildNodeName/></ChildNode>".
This is correct.
Please help.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|