我正在使用 linq 代码解析 XML 文件。这是我的代码。我想要绑定细节和图像是列表。
XmlSerializer serializer = new XmlSerializer(typeof(Notchs));
      XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
      Notchs notchs = (Notchs)serializer.Deserialize(xmlDoc.CreateReader());
      var query = from l in xmlDoc.Descendants("Category")
            select new Notch
            {
               name = (string)l.Attribute("name").Value,
               Titles = l.Element("Articles").Elements("article")
                         .Select(s => s.Attribute("title").ToString())
                         .ToList(),
               Image = l.Element("Articles").Elements("article").Elements("thumb_image").Elements("image")
                        .Select(x => x.Attribute("url").ToString()).ToList()
            };
      foreach (var result in query)
      {
          Console.WriteLine(result.name);
          foreach (var detail in result.Titles)
          {
              Console.WriteLine(detail);
          }
      }
      NotchsList.ItemsSource = query.ToList();
我尝试了这段代码,但我得到了如下所示的输出..但我想要详细信息和图像是列表。
  name
  System.Collection.Generic.List'1[string.system]
  name
  System.Collection.Generic.List'1[string.system]