private void RibbonBtnPersonMut_Click(object sender, RoutedEventArgs e) { PersonWindow pwin = new PersonWindow(); var collectionViewSource = pwin.FindResource("Teams") as CollectionViewSource; collectionViewSource.Source = context.Teams.ToList <Team>(); Person p = PersonenListView.SelectedItem as Person; if (p == null) { this.ShowMessageAsync("Hinweis: Person mutieren", "Keine Person ausgewählt"); } else { pwin.DataContext = p; pwin.ShowDialog(); if (pwin.DialogResult.HasValue && pwin.DialogResult.Value) { context.SaveChanges(); } else { context.Entry <Person>(p).State = EntityState.Unchanged; PersonenListView.Items.Refresh(); } } }
private void RibbonBtnPersonNeu_Click(object sender, RoutedEventArgs e) { PersonWindow pwin = new PersonWindow(); Person newPerson = new Person(); pwin.DataContext = newPerson; var collectionViewSource = pwin.FindResource("Teams") as CollectionViewSource; collectionViewSource.Source = context.Teams.ToList <Team>(); pwin.ShowDialog(); if (pwin.DialogResult.HasValue && pwin.DialogResult.Value) { context.Personen.Add(newPerson); context.SaveChanges(); } else { } }
void PersonListViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Person p = ((ListViewItem)sender).Content as Person; PersonWindow pwin = new PersonWindow(); var collectionViewSource = pwin.FindResource("Teams") as CollectionViewSource; collectionViewSource.Source = context.Teams.ToList <Team>(); pwin.DataContext = p; pwin.ShowDialog(); if (pwin.DialogResult.HasValue && pwin.DialogResult.Value) { context.SaveChanges(); } else { context.Entry <Person>(p).State = EntityState.Unchanged; PersonenListView.Items.Refresh(); } }