我使用Entity Framework
作爲我的數據庫源,並且需要將Linq
查詢「var」類型轉換爲ObservableCollection。然後我需要將ObservableCollection綁定到WPF窗體上的ComboBox;綁定到ItemsSource,DisplayMemeberPath,SelectedValuePath和SelectedValue。將ObservableCollection綁定到WPF中的組合框中
這裏是編碼:
using (PulseContext pc = new PulseContext())
{
var maritalcodes = from m in pc.CodeMaster
where m.Type == "16"
select new { m.Code, m.Description };
prop.ClientData.Options = new ObservableCollection<object>(maritalcodes);
}
問題是ComboBox
是表示本爲「{代碼= ????,描述= ????}」,而不是結合的代碼值和說明顯示。我需要做些什麼才能讓ComboBox綁定到單個元素上?
您應該將您的問題的最佳答案標記爲您接受的答案。 – 2012-07-23 19:00:46