Handle closing of window
This commit is contained in:
@ -2,6 +2,7 @@ using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -30,6 +31,7 @@ namespace Elwig.Windows {
|
||||
LockContext = IsEditing;
|
||||
}
|
||||
}
|
||||
protected bool IsClosing { get; private set; }
|
||||
|
||||
private TextBox[] TextBoxInputs;
|
||||
private TextBox[] PlzInputs;
|
||||
@ -55,6 +57,7 @@ namespace Elwig.Windows {
|
||||
RadioButtonInputs = Array.Empty<RadioButton>();
|
||||
Valid = new();
|
||||
OriginalValues = new();
|
||||
Closing += OnClosing;
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
|
||||
@ -75,6 +78,10 @@ namespace Elwig.Windows {
|
||||
ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
private void OnClosing(object? sender, CancelEventArgs evt) {
|
||||
IsClosing = true;
|
||||
}
|
||||
|
||||
private ComboBox GetPlzOrtInput(TextBox input) {
|
||||
return PlzOrtInputs[Array.IndexOf(PlzInputs, input)];
|
||||
}
|
||||
@ -244,7 +251,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected bool InputLostFocus(TextBox input, ValidationResult res, string? msg = null) {
|
||||
if (!res.IsValid)
|
||||
if (!res.IsValid && !IsClosing)
|
||||
System.Windows.MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return res.IsValid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user