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

查看:882
本文介绍了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>



我试图映射头DataGrid标题,行到行.. ,唯一的事情是,我有点卡住,我的纲领性酒店中丢失,可能有人给我一个暗示什么照看?

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与XML源命名myXMLDoc。
,那么你可以将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天全站免登陆