我需要什么 Linq to XML 将 XML 绑定到 Silverlight Datagrid
我正在查看这个问题和它给了我大约 80% 的需要。对我来说,“问题”是我的 XML 结构不同,我不太确定如何使用 Linq 来获得我需要的东西。
我的 XML 看起来像这样(顺便说一句,它是由 ConvertTo-XMl PowerShell Cmdlet 生成的)
<?xml version="1.0"?>
<Objects>
<Object>
<Property Name="Name">CompiledCode.ps1</Property>
<Property Name="LastWriteTime">5/21/2009 6:59:16 PM</Property>
</Object>
<Object>
<Property Name="Name">ComputerDrawing.ps1</Property>
<Property Name="LastWriteTime">1/13/2010 7:52:44 AM</Property>
</Object>
</Objects>
我试图绑定到 Silverlight DataGrid,以便列名称为“Name”和“LastWriteTime”,并且行将具有值那是在属性标签中。对于第一个,名称为 Compiled Code.ps1 ,LastWriteTime 为“5/21/2009 6:59:16 PM”
上述问题的答案采用了此方法
private Status GetStatus(XElement el)
{
Status s = new Status();
s.Description = el.Attribute("Description").Value;
s.Date = DateTime.Parse(el.Attribute("Date").Value);
return s;
}
我创建了自己的名为 Scripts 的类,它有一个名称和日期,但我试图弄清楚需要哪些元素或属性来填充数据网格。
I was looking at this question and it gave me about 80% of what I needed. The "problem" for me is that my XML is strucutred differently and I am not quite sure how I would go about using Linq to get at what I need.
My XML looks like this (By the way, its generated by the ConvertTo-XMl PowerShell Cmdlet)
<?xml version="1.0"?>
<Objects>
<Object>
<Property Name="Name">CompiledCode.ps1</Property>
<Property Name="LastWriteTime">5/21/2009 6:59:16 PM</Property>
</Object>
<Object>
<Property Name="Name">ComputerDrawing.ps1</Property>
<Property Name="LastWriteTime">1/13/2010 7:52:44 AM</Property>
</Object>
</Objects>
I am trying to bind to a Silverlight DataGrid so that the column names will be "Name" and "LastWriteTime" and the rows will have the vale that is in the Property Tag. For the first one, the name would be Compiled Code.ps1 and LastWriteTime would be "5/21/2009 6:59:16 PM"
The answer to the above mentioned question had this method
private Status GetStatus(XElement el)
{
Status s = new Status();
s.Description = el.Attribute("Description").Value;
s.Date = DateTime.Parse(el.Attribute("Date").Value);
return s;
}
I created my own class called Scripts which has a Name and a Date, but I am trying to figure out what elements or attributes I need to populate my datagrid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您需要的基本要点:-
您可能希望
LastWriteTime
成为DateTime
因此您可能希望将 is 放在中间字符串中并使用精确解析。This is the basic gist of what you need:-
You would probably want
LastWriteTime
to be aDateTime
so you might want to place is in an intermediatory string and use a parse exact.