WPF Datagrid binding to xml

前端 未结 2 1289
梦谈多话
梦谈多话 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:17

    I suppose you already have xmldataprovider with your Xml source named myXMLDoc. then you can bind xml data to your WPF controls.

    ItemsSource="{Binding Source={StaticResource myXMLDoc}, XPath=row}}" //bind "row" elements to your control
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题