简体   繁体   English

与Listview和XmlDataprovider的TwoWayBinding

[英]TwoWayBinding with Listview and XmlDataprovider

I searched a lot but I didn't find a solution for my problem. 我搜索了很多,但我找不到解决问题的方法。

I have an XML-File 我有一个XML文件

<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) 这就是我的问题:我想将这个XML文件绑定到listview,在那里我可以看到displayname和一个复选框,我可以(un)检查标签(双向绑定)

my XAML-file: 我的XAML文件:

<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? 但listview只显示第一个项目“display1”而不是第二个..任何人都知道为什么? (could there be any problem because I have (another) xmldataprovider?) (可能有任何问题,因为我有(另一个)xmldataprovider?)

thanks 谢谢
ps: sorry, english is not my first language ;) ps:抱歉,英语不是我的第一语言;)

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. 我看到你的问题是什么......如果通过在XAML中定义项目来设置Items集合(这就是你正在做的事情)......那么你也不允许设置ItemsSource

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. 带走ListViewItem ...并通过为ListView定义.View.ItemsTemplate来定义您希望项目的显示方式,以便它知道如何显示您的项目。

See here: 看这里:


Use the XmlDataProvider as follows: 使用XmlDataProvider ,如下所示:

If you want to be able to create new nodes in the XML document then use this: 如果您希望能够在XML文档中创建新节点,请使用以下命令:

And bind to the items in your document: 并绑定到文档中的项目:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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