TwoWayBinding与Listview和XmlDataprovider [英] TwoWayBinding with Listview and 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
,以便它知道如何显示您的项目。
看到这里:
-
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 /
使用 XmlDataProvider
如下:
如果您想要在XML文档中创建新节点,请使用以下命令:
并绑定到文档中的项目:
-
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
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:
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 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:
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
这篇关于TwoWayBinding与Listview和XmlDataprovider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!