简体   繁体   English

将原始XML绑定到WPF中的datagrid

[英]Binding raw XML to datagrid in WPF

I want to bind raw xml file to datagrid and to display that on WPF form using C#. 我想将原始xml文件绑定到datagrid并使用C#在WPF表单上显示它。 I planed to use dataset to store my xml, and then bind dataset to datagrid. 我计划使用数据集来存储我的xml,然后将数据集绑定到datagrid。 My xml look something like this 我的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>

i plan to use two datagrids one for and one for with columns id, name, movesLeft, won, completed tied to element 我打算使用两个数据网格,一个用于列id,name,movesLeft,won,完成绑定到元素

Best place to start would be with the XmlTextReader class (System.Xml) 最好的起点是XmlTextReader类(System.Xml)

Best resource I found for this is straight from MS XmlTextReader Link It lets you read the xml file and parse through it by element type/name/etc. 我发现的最佳资源来自MS XmlTextReader链接它允许您读取xml文件并通过元素类型/名称/等解析它。

Hope this helps. 希望这可以帮助。

From there, you can parse those to DataTables as normal and then bind them to the grid, also as normal. 从那里,您可以像往常一样将它们解析为DataTables,然后将它们绑定到网格,也正常。 If you need info on that too, let me know 如果您也需要相关信息,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM