Enlace bidireccional con Listview y XmlDataprovider

I searched a lot but I didn't find a solution for my problem.

I have an XML-File

    <tag tagname="tag1" displayname="display1">True</tag>
    <tag tagname="tag2" displayname="dispaly2">False</tag>

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">
                            <CheckBox IsChecked="{Binding XPath=./Module/Accounting/tag}">
                                <TextBlock Text="{Binding XPath=./Module/Accounting/tag/@displayname}"/>

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?)

ps: sorry, english is not my first language ;)

preguntado el 31 de julio de 12 a las 13:07

Use el ListView.ItemsSource Property for binding a list. -

If you are using a single column then I suggest to use ListBox. If you are planning to display multiple columns then refer proper setup of XAML ListView... switchonthecode.com/tutorials/… -

I tried it some time ago, but if I set the ItemsSource-Property in the listview I get the Exception "Items collection must be empty before using ItemsSource" -

1 Respuestas


I see what your problem is...if you set the Items collection by defining an item in XAML (which is what you are doing)...then you aren't allowed to set an ItemsSource también.

Quita el ListViewItem...and define how you want your items to appear by defining .View or .ItemsTemplate para su ListView so that it knows how to display your items.

Mira aquí:

Use el XmlDataProvider como sigue:

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:

Respondido el 17 de junio de 13 a las 23:06

But I do have an xmldataprovider, which is set to another listview - so I can't use this xmldataprovider because I want to select other data?! should I create a second xmldataprovider? - user1565745

Are you saying you have 2 listviews looking at the XML data at the same time?...and our they both using the XmlDataProvider in there ItemsSource? - Csmith

I have 2 listviews looking at the XML data, but only 1 listview uses the XmlDataProvider (Because I want to see different Values in the listviews) - user1565745

You were setting an item, so then it stopped you using ItemsSource....see answer above. - Csmith

but if I set the ItemsSource-Property in the listview I get the Exception "Items collection must be empty before using ItemsSource"?! - user1565745

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.