WPF将XMLDocument绑定到ListView [英] WPF bind XMLDocument to ListView

查看:66
本文介绍了WPF将XMLDocument绑定到ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有两个星期的大问题了
我正在尝试在WPF C#中创建一个应用程序,该应用程序读取xml文件和
创建一个XMLTreeVview树.现在,我设法创建了一个listview项目到XMLTreeVview树的绑定
但它不具有仅绑定特定节点项的功能.就像我在ListView1中有2个列表对象一样,我只希望将文件夹绑定,并且当我单击特定文件夹时,与之对应的核心项目将双向绑定到LISTVIEW2.谁能帮我即时解决这个问题

这是C#绑定代码

Hi guys
I have a huge problem for 2 weeks now
I am trying to create an application in WPF C# that reads in the xml file and
creates a XMLTreeVview tree. Now I managed to create a binding of my listview Items to the XMLTreeVview tree
but it doesnt have the capability to bind only the SPECIFIC Node Items. Like I have 2 list vies in ListView1 i want only the Folders to be binded and when i click on the specific folder the coresponding ITEMS will be binded twoway to the LISTVIEW2. can anyone please help me im getting readlly frustrated with this issue

here is the C# binding code

ListView2.ItemsSource = xtv.sourceXml.DocumentElement.ChildNodes;


XAML代码


XAML Code

<listview name="ListView2">
   <listview.itemtemplate>
     <datetemplate>
         <textbox text="Binding InnerText" />
      </datatemplate>
   </listview.itemtemplate>
</listview>



这是第二个ListView的C#绑定代码.



here is the C# binding code for second ListView

XMLTreeVview  xtv; //this has been returned from the file reader
ListView1.ItemsSource = xtv.sourceXml.DocumentElement.ChildNodes;



XAML代码



XAML Code

<listview name="ListView1">
   <listview.itemtemplate>
     <datetemplate>
         <textbox text="Binding FirstChild" />
      <datatemplate>
   </listview.itemtemplate>
</listview>



但是我真正想要的是仅文件夹列表,所以当我单击文件夹时,所有内部文本/项目都将出现在ListView2



BUT what i really want here is the List of ONLY the Folders, so when i click on the folder then all the Inner Text/Item will appear in ListView2

推荐答案

Hi ,

我认为您应该阅读以下从LINQ到XML的示例,
它会很快解决您的问题.

http://www.programmersheaven.com/2/CSharp3-4 [ http://msdn.microsoft.com/en-US/library/bb387098.aspx [ ^ ]

问候
Hi,

I think you should read following examples from LINQ to XML,
it''ll solve your problem quite quickly.

http://www.programmersheaven.com/2/CSharp3-4[^]

http://msdn.microsoft.com/en-US/library/bb387098.aspx[^]

Regards


您好,感谢您的答复,但我正在努力绑定位于文件夹中的特定项目,但我看不到LINQ能够做到这一点.我必须能够将C#代码中的节点绑定在后面吗?我将在Listview中使用isSelectionChenged事件的地方
Hi thanks for reply but im working on binding a specific items that are located in the folder but i dont see LINQ being able to do this. I have to be able to bind the node in the C# code behind right? where i would use isSelectionChenged event from Listview


,似乎当我将xmlTreeView绑定到List视图时,我不能仅绑定文件夹.我已经使用listView2.ItemsSource通过将其类型转换为ListNode然后绑定它来绑定我的XmlTireeView,但是当我仅尝试绑定SubFolders时,我无法达到此目的,我使用了treeView
如果(xtn.HasChildNode)
ListView2.ItemsSource = xtn.ChildNode;

但由于某些原因,这不起作用
我尝试将"xtn"子文件夹的层提取到另一个NodeList上,但是无法将XmlTreeview解析为XmlNodeList
it seems that when i bind the xmlTreeView to the List view I am not able to only bind the Folders. I have used the listView2.ItemsSource to bind my XmlTireeView by type converting it to ListNode then binding it, but when ii try to bind the SubFolders ONLY i can not achive this, I used my treeView
If (xtn.HasChildNode)
ListView2.ItemsSource = xtn.ChildNode;

but fore some reason this Doesnt work
I tried to Extract a layer of the "xtn" sub folders onto another NodeList but I cant parst an XmlTreeview to XmlNodeList


这篇关于WPF将XMLDocument绑定到ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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