简体   繁体   中英

TwoWayBinding with Listview and XmlDataprovider

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 Items collection by defining an item in XAML (which is what you are doing)...then you aren't allowed to set an ItemsSource as well.

Take away the ListViewItem ...and define how you want your items to appear by defining .View or .ItemsTemplate for your ListView so that it knows how to display your items.

See here:


Use the XmlDataProvider as 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM