WPF Datagrid 绑定到 xml [英] WPF Datagrid binding to xml

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

问题描述

我想以编程方式将包含从数据库中提取的一些结果的 XML 文件绑定到我的 Datagrid.我的 XML 看起来像:

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

<root>
    <resultset>
        <header>
            <column> Col 1 </column>
            <column> Col 2 </column>
        </header>

        <data>
            <row>
               <field>Value field 1</field>
               <field>Value field 2</field>
            </row>
            <row>
               <field>Value field 1</field>
               <field>Value field 2</field>
            </row>
        </data>
    </resultset>
</root>

我正在尝试将标题映射到数据网格标题,将行映射到行......唯一的问题是我有点卡住了,我在编程属性中迷失了,有人可以给我吗提示要照顾什么?

I'm trying to map the header to the datagrid header, and the rows to the rows... The only thing is that I'm kinda stuck, I'm lost among the programmatic properties, could someone just give me a hint to what to look after?

我尝试过:

myDataGrid.ItemsSource = myXmlDoc

但它并没有真正帮助任何东西出现嘿嘿,我已经阅读了一些路径"绑定属性,但我找不到它.

But it doesn't really help nothing shows up hehe, I've read about some "path" binding property but I can't find it.

推荐答案

我想您已经有了 xmldataprovider 和名为 myXMLDoc 的 Xml 源.然后您可以将 xml 数据绑定到您的 WPF 控件.

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

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

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