private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (Selected == null) { MessageBox.Show("Select configuration", "Not selected", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } SettingsWindow window = new SettingsWindow(); var selectedItem = Selected; ModelSettings settingsCopy = Selected.MakeCopy(); window.DataContext = selectedItem; window.Owner = this; window.ShowDialog(); if (window.DialogResult == true) { _fileHelper.SaveSetting(selectedItem); } else { bool isActiveConfig = MainViewModel.ActiveConfigutaion == selectedItem; int currentIdx = Items.IndexOf(selectedItem); Items[currentIdx] = settingsCopy; Selected = settingsCopy; if (isActiveConfig) MainViewModel.ActiveConfigutaion = settingsCopy; } }
private void ButtonNew_Click(object sender, RoutedEventArgs e) { ModelSettings model = new ModelSettings() { Name = "Data File Settings" }; SettingsWindow window = new SettingsWindow(); window.DataContext = model; window.Owner = this; window.ShowDialog(); if (window.DialogResult == true) { _fileHelper.SaveSetting(model); Items.Add(model); } }