Extract ControlUtils from Utils
This commit is contained in:
@ -63,13 +63,13 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs evt) {
|
||||
TextBoxInputs = Utils.FindAllChildren<TextBox>(this, ExemptInputs).ToArray();
|
||||
ComboBoxInputs = Utils.FindAllChildren<ComboBox>(this, ExemptInputs).ToArray();
|
||||
CheckBoxInputs = Utils.FindAllChildren<CheckBox>(this, ExemptInputs).ToArray();
|
||||
CheckComboBoxInputs = Utils.FindAllChildren<CheckComboBox>(this, ExemptInputs).ToArray();
|
||||
RadioButtonInputs = Utils.FindAllChildren<RadioButton>(this, ExemptInputs).ToArray();
|
||||
TextBoxInputs = ControlUtils.FindAllChildren<TextBox>(this, ExemptInputs).ToArray();
|
||||
ComboBoxInputs = ControlUtils.FindAllChildren<ComboBox>(this, ExemptInputs).ToArray();
|
||||
CheckBoxInputs = ControlUtils.FindAllChildren<CheckBox>(this, ExemptInputs).ToArray();
|
||||
CheckComboBoxInputs = ControlUtils.FindAllChildren<CheckComboBox>(this, ExemptInputs).ToArray();
|
||||
RadioButtonInputs = ControlUtils.FindAllChildren<RadioButton>(this, ExemptInputs).ToArray();
|
||||
PlzInputs = TextBoxInputs.Where(tb => "PLZ".Equals(tb.Tag)).ToArray();
|
||||
PlzOrtInputs = PlzInputs.Select(tb => Utils.FindNextSibling<ComboBox>(tb) ?? throw new MissingMemberException()).ToArray();
|
||||
PlzOrtInputs = PlzInputs.Select(tb => ControlUtils.FindNextSibling<ComboBox>(tb) ?? throw new MissingMemberException()).ToArray();
|
||||
foreach (var tb in TextBoxInputs)
|
||||
Valid[tb] = true;
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
@ -104,24 +104,24 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void ClearInputStates() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
Utils.ClearInputState(tb);
|
||||
ControlUtils.ClearInputState(tb);
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
Utils.ClearInputState(cb);
|
||||
ControlUtils.ClearInputState(cb);
|
||||
foreach (var ccb in CheckComboBoxInputs)
|
||||
Utils.ClearInputState(ccb);
|
||||
ControlUtils.ClearInputState(ccb);
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
Utils.ClearInputState(cb);
|
||||
ControlUtils.ClearInputState(cb);
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
Utils.ClearInputState(rb);
|
||||
ControlUtils.ClearInputState(rb);
|
||||
}
|
||||
|
||||
protected void ValidateRequiredInputs() {
|
||||
foreach (var input in RequiredInputs) {
|
||||
if (input is TextBox tb && tb.Text.Length == 0) {
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
Valid[input] = false;
|
||||
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) {
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -230,7 +230,7 @@ namespace Elwig.Windows {
|
||||
var plzInputValid = GetInputValid(plzInput);
|
||||
var item = ortInput.SelectedItem;
|
||||
var list = plzInputValid && plzInput.Text.Length == 4 ? Context.Postleitzahlen.Find(int.Parse(plzInput.Text))?.Orte.ToList() : null;
|
||||
Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
|
||||
ControlUtils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
|
||||
if (list != null && ortInput.SelectedItem == null && list.Count == 1)
|
||||
ortInput.SelectedItem = list[0];
|
||||
UpdateComboBox(ortInput);
|
||||
@ -264,12 +264,12 @@ namespace Elwig.Windows {
|
||||
ValidateInput(input, res.IsValid);
|
||||
if (res.IsValid) {
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
} else {
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
return res.IsValid;
|
||||
@ -292,11 +292,11 @@ namespace Elwig.Windows {
|
||||
protected void CheckBox_Changed(object sender, RoutedEventArgs evt) {
|
||||
var input = (CheckBox)sender;
|
||||
if (SenderIsRequired(input) && input.IsChecked != true) {
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -304,11 +304,11 @@ namespace Elwig.Windows {
|
||||
protected void RadioButton_Changed(object sender, RoutedEventArgs evt) {
|
||||
var input = (RadioButton)sender;
|
||||
if (SenderIsRequired(input) && input.IsChecked != true) {
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -317,13 +317,13 @@ namespace Elwig.Windows {
|
||||
var input = (TextBox)sender;
|
||||
if (SenderIsRequired(input) && input.Text.Length == 0) {
|
||||
ValidateInput(input, false);
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else {
|
||||
ValidateInput(input, true);
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
}
|
||||
UpdateButtons();
|
||||
@ -339,13 +339,13 @@ namespace Elwig.Windows {
|
||||
if (valid) {
|
||||
ValidateInput(input, true);
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
} else {
|
||||
ValidateInput(input, false);
|
||||
Utils.SetInputInvalid(input);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
Reference in New Issue
Block a user