none
自定义类型的赋值 RRS feed

  • 问题

  • 自定义的类,赋值老是失败!

        public SilverlightControl1()
        {
          InitializeComponent();
    
          OcList ol = new OcList();
          TreeView1.ItemsSource = ol;
    
        }
    
        public class OcList : ObservableCollection<aaa>
        {
          public OcList()
            : base()
          {
            for (int x = 0; x < 10; x++)
            {
              aaa a1 =
              new aaa
              {
                Name = "a" + x.ToString(),
                bbb = 
                  { 
                    new bbb 
                    { 
                      Name="b" + x.ToString (),
                      ccc = 
                      { 
                        new ccc 
                        { 
                          Name = "c" + x.ToString()
                        }
                      }
                    }
                  }
              };
    
              Add(a1);
            }
    
          }
        }
    
        public class aaa
        {
          public aaa()
          {
            bbb = new ObservableCollection<bbb>();
          }
    
          public string Name { get; set; }
          public ObservableCollection<bbb> bbb { get; set; }
        }
    
        public class bbb
        {
          public bbb()
          {
            ccc = new ObservableCollection<ccc>();
          }
    
          public string Name { get; set; }
          public ObservableCollection<ccc> ccc { get; set; }
        }
    
        public class ccc
        {
          public string Name { get; set; }
        }
      }
    2010年5月24日 10:08

答案

全部回复