1
            CarCollection cars = null;
            string path = @"F:\CustomDictionary.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(CarCollection));

            StreamReader reader = new StreamReader(path);
            cars = (CarCollection)serializer.Deserialize(reader);

            List<CarCollection> TrackCollection = new List<CarCollection>();
            TrackCollection.Add(cars);

            // model is the currently queried object, we return true or false according to the amount of children we have in our MyClasses List
            treeListView1.CanExpandGetter = model => ((CarCollection)model).
                                                          Car.Count() > 0;
            // We return the list of MyClasses that shall be considered Children.
            treeListView1.ChildrenGetter = delegate(object x) { return ((CarCollection)x).Car; };

            treeListView1.SetObjects(TrackCollection);

    [Serializable()]
    public class Car
    {
        [System.Xml.Serialization.XmlElement("StockNumber")]
        public string StockNumber { get; set; }

        [System.Xml.Serialization.XmlElement("Make")]
        public string Make { get; set; }

        [System.Xml.Serialization.XmlElement("Model")]
        public string Model { get; set; }
    }

    [Serializable()]
    [System.Xml.Serialization.XmlRoot("CarCollection")]
    public class CarCollection
    {
        [XmlArray("Cars")]
        [XmlArrayItem("Car", typeof(Car))]
        public Car[] Car { get; set; }
    }

我想Treelistview在运行显示后将xml文件绑定到上面编写的代码exception

“模型”不是“ObjectlistViewDemo.CarcCllection”的无参数方法字段或属性

引用下面的xml文件 引用下面的xml文件 引用下面的xml文件 引用下面的xml文件

<?xml version="1.0" encoding="utf-8"?>
<CarCollection>
  <Cars>
    <Car>
      <StockNumber>1020</StockNumber>
      <Make>Nissan</Make>
      <Model>Sentra</Model>
    </Car>
    <Car>
      <StockNumber>1010</StockNumber>
      <Make>Toyota</Make>
      <Model>Corolla</Model>
    </Car>
    <Car>
      <StockNumber>1111</StockNumber>
      <Make>Honda</Make>
      <Model>Accord</Model>
    </Car>
  </Cars>
</CarCollection>
4

0 回答 0