public class StudentList:ObservableCollection<Student>
{
public List<Student> studentList = new List<Student>();
public StudentList()
{
using (mydbEntities db = new mydbEntities())
{
var query = (from stu in db.mt1
select stu).ToList();
foreach (var q in query)
{
studentList.Add(new Student
{
Id = q.id,
Name = q.name
});
}
}
}
}
<Window.Resources>
<local:StudentList x:Key="studentListKey"/>
</Window.Resources>
<Grid>
<ComboBox x:Name="cmb" DataContext="{DynamicResource studentListKey}" DisplayMemberPath="Name"/>
</Grid>