我想将原始 xml 文件绑定(bind)到数据网格,并使用 C# 在 WPF 表单上显示它。我计划使用数据集来存储我的 xml,然后将数据集绑定(bind)到数据网格。我的 xml 看起来像这样
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<games>
<game id="123456" name="501">
<player id="1">
<name>john</name>
<score>495</score>
<movesLeft>15</movesLeft>
<won>No</won>
<completed>uncompleted</completed>
</player>
<player id="2">
<name>
konj
</name>
<score>501</score>
<movesLeft>15</movesLeft>
<won>No</won>
<completed>uncompleted</completed>
</player>
</game>
</games>
我计划使用两个数据网格,一个用于,一个用于 与列 id、name、movesLeft、won、completed 绑定(bind)到元素
最佳答案
最好的起点是 XmlTextReader 类 (System.Xml)
我为此找到的最佳资源直接来自 MS XmlTextReader Link 它允许您读取 xml 文件并按元素类型/名称/等解析它。
希望这对您有所帮助。
从那里,您可以像往常一样将它们解析为数据表,然后像往常一样将它们绑定(bind)到网格。如果您也需要这方面的信息,请告诉我
关于c# - 将原始 XML 绑定(bind)到 WPF 中的数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389670/