如何从实体将数据绑定到ComboBox

时间:2015-11-21 11:42:31

标签: c# wpf combobox entity

我有这段代码,但ComboBox中仍然没有数据。

using (var context = new DatabaseContext())
{
      var xd = (from c in context.CHall
                orderby c.CinemaHallName
                select c).ToList();
      foreach (var c in xd)
      {
           cbCinemaHall.ItemsSource = c.CinemaHallName;
           cbCinemaHall.DisplayMemberPath = "CinemaHallName";
      }                   
}

1 个答案:

答案 0 :(得分:1)

为此目的,您不需要foreach。只需将ItemsSource的{​​{1}}设置为ComboBox即可。像这样:

xd