public SettingsWindow() { ProgramSettings = null; InitializeComponent(); using (ConfigurationManager man = new ConfigurationManager()) { this.ProgramSettings = man.GetProgramSettings(); } this.Loaded += (s, e) => { stack1.DataContext = this.ProgramSettings; }; this.Closing += (s, e) => { if (ProgramSettings != null) ProgramSettings = null; (this.Owner as MainWindow).Focus(); }; }