public MainWindow() { InitializeComponent(); if (dataGrid.Items != null) { using (var context = new GoodContext()) { goods = context.Goods.ToList(); dataGrid.ItemsSource = goods; } } else if (dataGrid.Items == null) { dataGrid.ItemsSource = goods; } }
private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { using (var context = new GoodContext()) { context.Goods.Add(new Good { Id = id, Name = name, Price = price, Amount = amount }); context.SaveChanges(); } } }