WPF Datagrid binding to xml

前端 未结 2 1314
梦谈多话
梦谈多话 2021-01-17 04:51

I want to programmatically bind an XML file containing some results pulled out from database to my Datagrid. My XML looks like:

         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 05:19

    Is this what you're looking for?

    http://joshsmithonwpf.wordpress.com/2007/06/04/binding-to-xml/

    I think what you want to do is hook up ItemsSource to an XmlDataProvider (which you can also create in code), with its XPath set to /root/resultset/data/row. Then for each element you can use, say Text = {Binding XPath=./field}.

    I'm a little iffy on the details since I haven't done this in a while, but hopefully that'll set you in the right direction.

提交回复
热议问题