[#37] Controls: Implement CheckComboBox and remove xctk
All checks were successful
Test / Run tests (push) Successful in 2m26s

This commit is contained in:
2024-06-12 16:29:57 +02:00
parent 6fc38b9db0
commit 4483eb6a69
16 changed files with 308 additions and 94 deletions

View File

@ -1,4 +1,3 @@
using Elwig.Controls;
using Elwig.Helpers;
using Elwig.Models.Entities;
using System;
@ -10,7 +9,6 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using Xceed.Wpf.Toolkit;
using System.Windows.Input;
namespace Elwig.Windows {
@ -42,7 +40,7 @@ namespace Elwig.Windows {
private TextBox[] PlzInputs;
private ComboBox[] ComboBoxInputs;
private ComboBox[] PlzOrtInputs;
private CheckComboBox[] CheckComboBoxInputs;
private ListBox[] ListBoxInputs;
private CheckBox[] CheckBoxInputs;
private RadioButton[] RadioButtonInputs;
private readonly Dictionary<Control, bool> Valid;
@ -68,7 +66,7 @@ namespace Elwig.Windows {
TextBoxInputs = [];
PlzInputs = [];
ComboBoxInputs = [];
CheckComboBoxInputs = [];
ListBoxInputs = [];
PlzOrtInputs = [];
CheckBoxInputs = [];
RadioButtonInputs = [];
@ -97,7 +95,7 @@ namespace Elwig.Windows {
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();
ListBoxInputs = ControlUtils.FindAllChildren<ListBox>(this, ExemptInputs).ToArray();
RadioButtonInputs = ControlUtils.FindAllChildren<RadioButton>(this, ExemptInputs).ToArray();
PlzInputs = ControlUtils.FindAllChildren<TextBox>(this).Where(tb => "PLZ".Equals(tb.Tag)).ToArray();
PlzOrtInputs = PlzInputs.Select(tb => ControlUtils.FindNextSibling<ComboBox>(tb) ?? throw new MissingMemberException()).ToArray();
@ -105,8 +103,8 @@ namespace Elwig.Windows {
Valid[tb] = true;
foreach (var cb in ComboBoxInputs)
cb.SelectionChanged += ComboBox_SelectionChanged;
foreach (var cb in CheckComboBoxInputs)
cb.ItemSelectionChanged += ComboBox_SelectionChanged;
foreach (var lb in ListBoxInputs)
lb.SelectionChanged += ComboBox_SelectionChanged;
}
private void OnClosing(object? sender, CancelEventArgs evt) {
@ -151,8 +149,8 @@ namespace Elwig.Windows {
ControlUtils.ClearInputState(tb);
foreach (var cb in ComboBoxInputs)
ControlUtils.ClearInputState(cb);
foreach (var ccb in CheckComboBoxInputs)
ControlUtils.ClearInputState(ccb);
foreach (var lb in ListBoxInputs)
ControlUtils.ClearInputState(lb);
foreach (var cb in CheckBoxInputs)
ControlUtils.ClearInputState(cb);
foreach (var rb in RadioButtonInputs)
@ -166,7 +164,7 @@ namespace Elwig.Windows {
Valid[input] = false;
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) {
ControlUtils.SetInputInvalid(input);
} else if (input is CheckComboBox ccb && ccb.SelectedItem == null && ccb.ItemsSource != null) {
} else if (input is ListBox lb && lb.SelectedItem == null && lb.ItemsSource != null) {
ControlUtils.SetInputInvalid(input);
} else if (input is CheckBox ckb && ckb.IsChecked != true) {
ControlUtils.SetInputInvalid(input);
@ -190,8 +188,8 @@ namespace Elwig.Windows {
tb.IsReadOnly = true;
foreach (var cb in ComboBoxInputs)
cb.IsEnabled = false;
foreach (var ccb in CheckComboBoxInputs)
ccb.IsEnabled = false;
foreach (var lb in ListBoxInputs)
lb.IsEnabled = false;
foreach (var cb in CheckBoxInputs)
cb.IsEnabled = false;
foreach (var rb in RadioButtonInputs)
@ -203,8 +201,8 @@ namespace Elwig.Windows {
tb.IsReadOnly = false;
foreach (var cb in ComboBoxInputs)
cb.IsEnabled = true;
foreach (var ccb in CheckComboBoxInputs)
ccb.IsEnabled = true;
foreach (var lb in ListBoxInputs)
lb.IsEnabled = true;
foreach (var cb in CheckBoxInputs)
cb.IsEnabled = true;
foreach (var rb in RadioButtonInputs)
@ -224,8 +222,8 @@ namespace Elwig.Windows {
OriginalValues[tb] = ControlUtils.GetInputHashCode(tb);
foreach (var cb in ComboBoxInputs)
OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
foreach (var ccb in CheckComboBoxInputs)
OriginalValues[ccb] = ControlUtils.GetInputHashCode(ccb);
foreach (var lb in ListBoxInputs)
OriginalValues[lb] = ControlUtils.GetInputHashCode(lb);
foreach (var cb in CheckBoxInputs)
OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
foreach (var rb in RadioButtonInputs)
@ -277,8 +275,8 @@ namespace Elwig.Windows {
tb.Text = "";
foreach (var cb in ComboBoxInputs)
cb.SelectedItem = null;
foreach (var ccb in CheckComboBoxInputs)
ccb.SelectedItems.Clear();
foreach (var lb in ListBoxInputs)
lb.SelectedItems.Clear();
foreach (var cb in CheckBoxInputs)
cb.IsChecked = cb.IsThreeState ? null : false;
foreach (var rb in RadioButtonInputs)
@ -315,13 +313,13 @@ namespace Elwig.Windows {
!IsValid ||
TextBoxInputs.Any(InputHasChanged) ||
ComboBoxInputs.Any(InputHasChanged) ||
CheckComboBoxInputs.Any(InputHasChanged) ||
ListBoxInputs.Any(InputHasChanged) ||
CheckBoxInputs.Any(InputHasChanged) ||
RadioButtonInputs.Any(InputHasChanged)
) || IsCreating && (
TextBoxInputs.Any(i => InputIsNotDefault(i) || (!i.IsReadOnly && i.Text != "")) ||
ComboBoxInputs.Any(i => InputIsNotDefault(i) || (i.IsEnabled && i.SelectedItem != null)) ||
CheckComboBoxInputs.Any(i => InputIsNotDefault(i) || i.SelectedItem != null) ||
ListBoxInputs.Any(i => InputIsNotDefault(i) || i.SelectedItem != null) ||
CheckBoxInputs.Any(InputIsNotDefault) ||
RadioButtonInputs.Any(InputIsNotDefault)
);
@ -447,8 +445,8 @@ namespace Elwig.Windows {
bool valid = false;
if (input is ComboBox cb) {
valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input);
} else if (input is CheckComboBox ccb) {
valid = ccb.ItemsSource == null || ccb.SelectedItem != null || !RequiredInputs.Contains(input);
} else if (input is ListBox lb) {
valid = lb.ItemsSource == null || lb.SelectedItem != null || !RequiredInputs.Contains(input);
}
if (valid) {
ValidateInput(input, true);