TwoWayBinding与Listview和XmlDataprovider [英] TwoWayBinding with Listview and XmlDataprovider

查看:115
本文介绍了TwoWayBinding与Listview和XmlDataprovider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多,但是我没有找到解决问题的方法。



我有一个XML文件

 <模块> 
< Accounting>
< tag tagname =tag1displayname =display1> True< / tag>
< tag tagname =tag2displayname =dispaly2> False< / tag>
< / Accounting>
< / Module>

这是我的问题:
我想将此XML文件绑定到列表视图我可以看到displayname和一个复选框,我可以(un)检查标签(双向绑定)



我的XAML文件:

 < ListView Height =134.113Width =227.409Margin =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>

但是列表视图只显示第一个项目display1,而不是第二个项目..任何人的想法为什么?
(可能有任何问题,因为我有(另一个)xmldataprovider?)



谢谢

ps:对不起,英文不是我的第一语言;)

解决方案

更新:



问题是...如果您通过在XAML中定义一个项目(这是您正在做的),您设置项目集合,那么您不能设置 ItemsSource



取走 ListViewItem 。 ..并通过定义 .View .ItemsTemplate 为您的 ListView ,以便它知道如何显示您的项目。



看到这里:








使用 XmlDataProvider 如下:





如果您想要在XML文档中创建新节点,请使用以下命令:





并绑定到文档中的项目:




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:

这篇关于TwoWayBinding与Listview和XmlDataprovider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆