2012-07-10 101 views
0

型DataGrid列的是組合框,我創建列表,並列出該行,有點如果我在XAML寫在數據網格不綁定路徑(WPF)

ItemsSource="{Binding Path=combolist}" 

項目爲空 我的名單

List<string> combolist = new List<string>(); 
      while (reader.Read()) 
      { 
       combolist.Add(reader.GetString(0)); 
      } 

爲什麼項目爲空?

+0

你有物業combolist?你認爲什麼是datacontext? – 2012-07-10 08:40:22

+0

你在哪裏聲明'combolist',它是一個屬性或字段? ComboBox的'DataContext'是什麼?請給我們更多的信息 – 2012-07-10 08:40:50

+0

combolist其'List' ... WTF!? – MexVl 2012-07-10 08:47:09

回答

0

combolist必須是財產。它應該在View Model之內。 (國際海事組織,它應該是ComboList)。

0

結合只是爲了公共屬性工作。

public List<string> Combolist {get;set} 

    //ctor 
    this.Combolist = new List<string>(); 
    while (reader.Read()) 
     { 
      Combolist .Add(reader.GetString(0)); 
     } 

    this.DataContext = this; 

!如果您不填寫構造函數列表,你應該使用列表的ObservableCollection。