private void EditViewModel <T>(Collection <T> collection, T viewModel, NonModalDialogWindow window) where T : ViewModelBase { if (this.currentlyEditedViewModels.ContainsKey(viewModel)) { this.currentlyEditedViewModels[viewModel].Activate(); } else { this.currentlyEditedViewModels.Add(viewModel, window); this.SetValue(MainWindow.IsEditingPropertyKey, this.currentlyEditedViewModels.Count > 0); window.Closed += (sender, e) => { if (window.ApplyChanges) { collection.Replace(viewModel, (T)window.DataContext); } this.currentlyEditedViewModels.Remove(viewModel); this.SetValue(MainWindow.IsEditingPropertyKey, this.currentlyEditedViewModels.Count > 0); }; window.Show(); } }
private void AddViewModel <T>(Collection <T> collection, T viewModel, NonModalDialogWindow window) where T : ViewModelBase { window.Closed += (sender, e) => { if (window.ApplyChanges) { collection.Add(viewModel); } this.currentlyEditedViewModels.Remove(viewModel); this.SetValue(MainWindow.IsEditingPropertyKey, this.currentlyEditedViewModels.Count > 0); }; this.currentlyEditedViewModels.Add(viewModel, window); this.SetValue(MainWindow.IsEditingPropertyKey, this.currentlyEditedViewModels.Count > 0); window.Show(); }