private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { // The function may be called, while the window has not been created completely. // So we have to check, if the button can already be referenced. if (SaveButton != null) { // Check if textBox1 is empty or // textBox1.text is already in the list of saved strings. if (string.IsNullOrWhiteSpace(textBox1.Text) || SavedTextBoxTexts.IndexOf(textBox1.Text) >= 0) { // Disable Button SaveButton.IsEnabled = false; if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { } } else { // If textBox1.text has not been saved already // or is an empty string or a string of whitespaces, // enable the SaveButton (again). SaveButton.IsEnabled = true; } } }
// This is executed, when the other button has been clicked. // The text in textBox1 will not be saved. private void AnotherButton_Click(object sender, RoutedEventArgs e) { if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { // Move to other page ... } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (SaveButton != null) { if (!string.IsNullOrWhiteSpace(textBox1.Text) || textBox1.Text == TextBoxDefaultValue) { SaveButton.IsEnabled = false; if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { } } } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (SaveButton != null) { if (string.IsNullOrWhiteSpace(textBox1.Text) || SavedTextBoxTexts.IndexOf(textBox1.Text) >= 0) { SaveButton.IsEnabled = false; if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { } } else { SaveButton.IsEnabled = true; } } }