WPF数据网格绑定时不更新更改

时间:2019-06-19 17:19:09

标签: c# wpf entity-framework

我有一个数据网格,当更改组合框选择时,将直接使用组合框中的项目(绑定到实体框架上下文中的对象)来加载该数据网格。但是,当我在数据网格上编辑/添加/删除并尝试保存更改时,它什么也没做,所以我想知道如何解决此问题

public class ProgramControl: DbContext
{
    public DbSet<Asignaturas> Asigns { get; set; }

    public DbSet<Alumno> Alumnos { get; set; }

    public DbSet<Profesor> Profes { get; set; }

    public DbSet<Aula> Aulas { get; set; }

    public DbSet<Curso> Cursos { get; set; }
    public DbSet<Calificacion> Califications { get; set; }

    public ProgramControl()
    {
    }
}

public class Asignaturas
{
    [Key]
    public string Asign { get; set; }
    public List<string> correlativas = new List<string>();
    public List<Alumno> inscriptos = new List<Alumno>();
}
private void AlumnosPorMateria_Click(object sender, RoutedEventArgs e)
{
    legajoAlumno.Visibility = Visibility.Collapsed;
    elegirCursoTexto.Visibility = Visibility.Visible;
    elegirAsig.Visibility = Visibility.Visible;
    elegirCursoTexto.Text = "Elija la materia de la que desea ver los alumnos";
    var dset = db.Asigns;
    DbSet<Asignaturas> qry = dset;
    qry.Load();

    elegirAsig.ItemsSource = dset.Local.ToBindingList();
    alumnosGrid.Visibility = Visibility.Collapsed;
    confirmButton.Visibility = Visibility.Collapsed;
    cursoBox.Visibility = Visibility.Collapsed;
    confirmButton.Content = "Confirmar";
}

private void ElegirCurso_SelectionChanged(object sender, 
    SelectionChangedEventArgs e)
{
    Asignaturas asig =(Asignaturas)elegirAsig.SelectedItem;
    db.Asigns.Load();
    var dset = db.Asigns;
    DbSet<Asignaturas> qry = dset;
    qry.Load();
    foreach (var item in dset)
    {
        if (item.Asign.Equals(asig.Asign))
        {
            asig = item;
        }
    }

    alumnosGrid.Visibility = Visibility.Visible;
    alumnosGrid.ItemsSource = asig.inscriptos;

    confirmButton.Visibility = Visibility.Visible;
}

0 个答案:

没有答案