I searched a lot but I didn’t find a solution for my problem.
I have an XML-File
<Module>
<Accounting>
<tag tagname="tag1" displayname="display1">True</tag>
<tag tagname="tag2" displayname="dispaly2">False</tag>
</Accounting>
</Module>
And that’s my problem:
I want to bind this XML-File to a listview where I can see the displayname and a checkbox where I am able to (un)check the tag (two-way-binding)
my XAML-file:
<ListView Height="134.113" Width="227.409" Margin="0,-100,30,10">
<ListViewItem>
<StackPanel>
<CheckBox IsChecked="{Binding XPath=./Module/Accounting/tag}">
<TextBlock Text="{Binding XPath=./Module/Accounting/tag/@displayname}"/>
</CheckBox>
</StackPanel>
</ListViewItem>
</ListView>
But the listview only displays the first Item “display1” but not the second one.. anyone an idea why?
(could there be any problem because I have (another) xmldataprovider?)
thanks
ps: sorry, english is not my first language 😉
UPDATE:
I see what your problem is…if you set the
Itemscollection by defining an item in XAML (which is what you are doing)…then you aren’t allowed to set anItemsSourceas well.Take away the
ListViewItem…and define how you want your items to appear by defining.Viewor.ItemsTemplatefor yourListViewso that it knows how to display your items.See here:
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b47444b1-a566-4787-9364-a2fbff481354/
Use the
XmlDataProvideras follows:If you want to be able to create new nodes in the XML document then use this:
And bind to the items in your document:
http://dotnet-experience.blogspot.co.uk/2011/11/wpf-working-with-xml-and.html
http://blogs.msdn.com/b/ashish/archive/2006/09/19/762085.aspx