private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // If user has unsaved data ask them to confirm if they want to save first before closing. if (HasTxtChanged == true) { //Convert the Dialog so it is reusable for this instance AreYouSureDialog areYouSureDialog = new AreYouSureDialog(); areYouSureDialog.Main_Label.Text = "Would you like to save before closing?"; areYouSureDialog.Warning_Label.Text = ""; areYouSureDialog.AYSD_Cancel_Button.Content = "Dont Save"; areYouSureDialog.AYSD_Delete_Button.Content = "Save"; areYouSureDialog.IsThisToDelete = false; //Position window correctly areYouSureDialog.Owner = this; areYouSureDialog.WindowStartupLocation = WindowStartupLocation.Manual; areYouSureDialog.Top = Owner.Top + 300; areYouSureDialog.Left = Owner.Left + 450; areYouSureDialog.ShowDialog(); if (areYouSureDialog.DoesUserWantToSave == true) { Recipe_JsonHandler.WriteToJsonFile_Tips(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Tips\\TipsDocument.json", new TextRange(Tips_Rich_TextBox.Document.ContentStart, Tips_Rich_TextBox.Document.ContentEnd).Text.ToString()); HasTxtChanged = false; } } }
private void Save_Close_Button_Click(object sender, RoutedEventArgs e) { Recipe_JsonHandler.WriteToJsonFile_Tips(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Tips\\TipsDocument.json", new TextRange(Tips_Rich_TextBox.Document.ContentStart, Tips_Rich_TextBox.Document.ContentEnd).Text.ToString()); HasTxtChanged = false; this.Close(); }