private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (isDirty) { MessageBoxResult result = MessageBox.Show("Do you want to save your project?", "Project has Changed!", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { Save_Click(sender, null); } } var userPrefs = new UserPreferences(); userPrefs.WindowHeight = this.Height; userPrefs.WindowWidth = this.Width; userPrefs.WindowTop = this.Top; userPrefs.WindowLeft = this.Left; userPrefs.WindowState = this.WindowState; userPrefs.Save(); }