0
問題:我有一個簡單的cboBox調用PhoneTypes。我希望它的數據源理想地是從linq生成的一個sortedList,它從tblPhonetypes中提取數據。 我也想組合框被綁定。創建一個列表來填充Linq到SQL查詢的組合框
在主窗口中我有:
public partial class MainWindow : MetroWindow
{
public Window mainWindow;
public PhoneType selectedPhoneType { get; set; }
// do we need to have a getter/setter on a list to data bind to??
// public List<PhoneType> phonetypelist {get;set;)
// not sure if we need an implementation of data context here !
// DocITDatabaseEntities ctx = new DocITDatabaseEntities();
public MainWindow()
{
InitializeComponent();
DocITDatabaseEntities ctx = new DocITDatabaseEntities();
DataContext = this;
cboPtPhoneType.ItemsSource = phonetypelist;
cboPtPhoneType.DataContext = // todo;
}
private SortedList(int,string) phonelist()
{
DocITDatabaseEntities ctx = new DocITDatabaseEntities();
List<PhoneType> lstphones = from p in ctx.tblPhoneTypes
orderby p.charPhoneType
select p;
// To do...create the list and pass it to the combo box as the
}