protected override void OnClosed(EventArgs e) { base.OnClosed(e); FileGenerationConfiguration.SaveConfiguration(); GetSelectedConnection()?.Save(); BindingOperations.ClearAllBindings(cmBCurrentConnection); cmBCurrentConnection.Items.DetachFromSourceCollection(); cmBCurrentConnection.DataContext = null; cmBCurrentConnection.ItemsSource = null; }
protected override void OnClosed(EventArgs e) { base.OnClosed(e); FileGenerationConfiguration.SaveConfiguration(); (cmBConnection1.SelectedItem as ConnectionData)?.Save(); (cmBConnection2.SelectedItem as ConnectionData)?.Save(); BindingOperations.ClearAllBindings(cmBConnection1); cmBConnection1.Items.DetachFromSourceCollection(); cmBConnection1.DataContext = null; cmBConnection1.ItemsSource = null; BindingOperations.ClearAllBindings(cmBConnection2); cmBConnection2.Items.DetachFromSourceCollection(); cmBConnection2.DataContext = null; cmBConnection2.ItemsSource = null; }
private void btnLoadConfiguration_Click(object sender, System.Windows.RoutedEventArgs e) { if (this._fileGenerationOptions == null) { return; } string selectedPath = string.Empty; var thread = new Thread(() => { try { var openFileDialog1 = new Microsoft.Win32.OpenFileDialog { Filter = "FileGenerationOptions (.xml)|*.xml", FilterIndex = 1, RestoreDirectory = true }; if (openFileDialog1.ShowDialog().GetValueOrDefault()) { selectedPath = openFileDialog1.FileName; } } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(null, ex); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); if (string.IsNullOrEmpty(selectedPath)) { return; } FileGenerationOptions fileOptionFromDisk = null; try { fileOptionFromDisk = FileGenerationOptions.LoadFromPath(selectedPath); } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(null, ex); fileOptionFromDisk = null; } if (fileOptionFromDisk == null) { return; } this._fileGenerationOptions.LoadFromDisk(fileOptionFromDisk); FileGenerationConfiguration.SaveConfiguration(); }