diff --git a/Elwig/Controls/CheckComboBox.cs b/Elwig/Controls/CheckComboBox.cs new file mode 100644 index 0000000..395427c --- /dev/null +++ b/Elwig/Controls/CheckComboBox.cs @@ -0,0 +1,106 @@ +using System.Linq; +using System.Windows; +using System.Windows.Controls; + +namespace Elwig.Controls { + public class CheckComboBox : ListBox { + + public static readonly DependencyProperty DelimiterProperty = DependencyProperty.Register("Delimiter", typeof(string), typeof(CheckComboBox), new FrameworkPropertyMetadata(", ")); + public string Delimiter { + get => (string)GetValue(DelimiterProperty); + set => SetValue(DelimiterProperty, value); + } + + public static readonly DependencyProperty AllItemsSelectedContentProperty = DependencyProperty.Register("AllItemsSelectedContent", typeof(string), typeof(CheckComboBox), new FrameworkPropertyMetadata("All")); + public string AllItemsSelectedContent { + get => (string)GetValue(AllItemsSelectedContentProperty); + set => SetValue(AllItemsSelectedContentProperty, value); + } + + public static readonly DependencyProperty IsSelectAllActiveProperty = DependencyProperty.Register("IsSelectAllActive", typeof(bool), typeof(CheckComboBox), new FrameworkPropertyMetadata(false)); + public bool IsSelectAllActive { + get => (bool)GetValue(IsSelectAllActiveProperty); + set => SetValue(IsSelectAllActiveProperty, value); + } + + public static readonly DependencyProperty SelectAllContentProperty = DependencyProperty.Register("SelectAllContent", typeof(string), typeof(CheckComboBox), new FrameworkPropertyMetadata("All")); + public string SelectAllContent { + get => (string)GetValue(SelectAllContentProperty); + set => SetValue(SelectAllContentProperty, value); + } + + public static readonly DependencyProperty AllItemsSelectedProperty = DependencyProperty.Register("AllItemsSelected", typeof(bool?), typeof(CheckComboBox), new FrameworkPropertyMetadata(false)); + public bool? AllItemsSelected { + get => (bool?)GetValue(AllItemsSelectedProperty); + set => SetValue(AllItemsSelectedProperty, value); + } + + public static readonly DependencyProperty IsDropDownOpenProperty = DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(CheckComboBox), new FrameworkPropertyMetadata(false)); + public bool IsDropDownOpen { + get => (bool)GetValue(IsDropDownOpenProperty); + set => SetValue(IsDropDownOpenProperty, value); + } + + public static readonly DependencyProperty MaxDropDownHeightProperty = DependencyProperty.Register("MaxDropDownHeight", typeof(double), typeof(CheckComboBox), new FrameworkPropertyMetadata(ComboBox.MaxDropDownHeightProperty.DefaultMetadata.DefaultValue)); + public double MaxDropDownHeight { + get => (double)GetValue(MaxDropDownHeightProperty); + set => SetValue(MaxDropDownHeightProperty, value); + } + + static CheckComboBox() { + DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckComboBox), new FrameworkPropertyMetadata(typeof(CheckComboBox))); + } + + private TextBlock TextBox; + + public CheckComboBox() { + SelectionMode = SelectionMode.Multiple; + } + + public override void OnApplyTemplate() { + TextBox = (GetTemplateChild("TextBox") as TextBlock)!; + var button = GetTemplateChild("Button") as Button; + button!.Click += Button_MouseDown; + var item = GetTemplateChild("SelectAllItem") as ListBoxItem; + item!.PreviewMouseDown += SelectAllItem_MouseDown; + SelectionChanged += OnSelectionChanged; + IsEnabledChanged += OnIsEnabledChanged; + base.OnApplyTemplate(); + } + + private void Button_MouseDown(object sender, RoutedEventArgs evt) { + IsDropDownOpen = !IsDropDownOpen; + } + + private void SelectAllItem_MouseDown(object sender, RoutedEventArgs evt) { + if (AllItemsSelected == false) { + SelectAll(); + } else { + UnselectAll(); + } + evt.Handled = true; + } + + private void OnSelectionChanged(object sender, SelectionChangedEventArgs evt) { + var dmp = DisplayMemberPath != null && DisplayMemberPath != "" ? DisplayMemberPath : null; + if (SelectedItems.Count == ItemsSource.Cast().Count() && AllItemsSelectedContent != null) { + TextBox.Text = AllItemsSelectedContent; + AllItemsSelected = true; + } else if (SelectedItems.Count == 0) { + TextBox.Text = ""; + AllItemsSelected = false; + } else { + TextBox.Text = string.Join(Delimiter, + dmp == null ? SelectedItems.Cast() : + SelectedItems.Cast() + .Select(i => i.GetType().GetProperty(dmp)?.GetValue(i)) + ); + AllItemsSelected = null; + } + } + + private void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs evt) { + if (!IsEnabled) IsDropDownOpen = false; + } + } +} diff --git a/Elwig/Controls/CheckComboBox.xaml b/Elwig/Controls/CheckComboBox.xaml new file mode 100644 index 0000000..7e4d554 --- /dev/null +++ b/Elwig/Controls/CheckComboBox.xaml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Elwig/Controls/VisibilityConverter.cs b/Elwig/Controls/VisibilityConverter.cs new file mode 100644 index 0000000..8c8f3f3 --- /dev/null +++ b/Elwig/Controls/VisibilityConverter.cs @@ -0,0 +1,16 @@ +using System; +using System.Windows; +using System.Windows.Data; +using System.Globalization; + +namespace Elwig.Controls { + public class VisibilityConverter : IValueConverter { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + return (bool)value ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + return (Visibility)value == Visibility.Visible; + } + } +} diff --git a/Elwig/Elwig.csproj b/Elwig/Elwig.csproj index 6b7076e..ec83d5e 100644 --- a/Elwig/Elwig.csproj +++ b/Elwig/Elwig.csproj @@ -25,7 +25,6 @@ - diff --git a/Elwig/Helpers/ControlUtils.cs b/Elwig/Helpers/ControlUtils.cs index de449c4..89f210a 100644 --- a/Elwig/Helpers/ControlUtils.cs +++ b/Elwig/Helpers/ControlUtils.cs @@ -102,20 +102,6 @@ namespace Elwig.Helpers { selector.SelectedItem = selItem; } - public static void RenewItemsSource(Xceed.Wpf.Toolkit.Primitives.Selector selector, IEnumerable? source, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventHandler? handler = null) { - if (selector.ItemsSource == source) - return; - var selectedIds = selector.SelectedItems.Cast().Select(i => Utils.GetEntityIdentifier(i)).ToList(); - if (handler != null && selectedIds != null) selector.ItemSelectionChanged -= handler; - selector.ItemsSource = source; - if (source != null) { - selector.SelectedItems.Clear(); - foreach (var i in source.Cast().Where(i => selectedIds.Contains(Utils.GetEntityIdentifier(i)))) - selector.SelectedItems.Add(i); - } - if (handler != null && selectedIds != null) selector.ItemSelectionChanged += handler; - } - public static void RenewItemsSource(DataGrid dataGrid, IEnumerable? source, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None, bool keepSort = true) { if (dataGrid.ItemsSource == source) return; @@ -210,15 +196,15 @@ namespace Elwig.Helpers { return GetItemsFromSource(source, items.Select(Utils.GetEntityIdentifier)); } - public static void SelectItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, IEnumerable? ids) { - ccb.SelectedItems.Clear(); + public static void SelectItems(ListBox lb, IEnumerable? ids) { + lb.SelectedItems.Clear(); if (ids == null) return; foreach (var id in ids) - ccb.SelectedItems.Add(GetItemFromSource(ccb.ItemsSource, id)); + lb.SelectedItems.Add(GetItemFromSource(lb.ItemsSource, id)); } - public static void SelectItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, IEnumerable? items) { - SelectItems(ccb, items?.Select(Utils.GetEntityIdentifier)); + public static void SelectItems(ListBox lb, IEnumerable? items) { + SelectItems(lb, items?.Select(Utils.GetEntityIdentifier)); } public static int? GetInputHashCode(Control input) { @@ -226,8 +212,8 @@ namespace Elwig.Helpers { return Utils.GetEntityIdentifier(tb.Text); } else if (input is ComboBox sb) { return Utils.GetEntityIdentifier(sb.SelectedItem); - } else if (input is Xceed.Wpf.Toolkit.CheckComboBox ccb) { - return Utils.GetEntityIdentifier(ccb.SelectedItems); + } else if (input is ListBox lb) { + return Utils.GetEntityIdentifier(lb.SelectedItems); } else if (input is CheckBox cb) { return Utils.GetEntityIdentifier(cb.IsChecked); } else if (input is RadioButton rb) { diff --git a/Elwig/Themes/Generic.xaml b/Elwig/Themes/Generic.xaml index 4b3354d..aa3cb34 100644 --- a/Elwig/Themes/Generic.xaml +++ b/Elwig/Themes/Generic.xaml @@ -2,5 +2,6 @@ + diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index d57f983..7f44d91 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -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 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(this, ExemptInputs).ToArray(); ComboBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray(); CheckBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray(); - CheckComboBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray(); + ListBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray(); RadioButtonInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray(); PlzInputs = ControlUtils.FindAllChildren(this).Where(tb => "PLZ".Equals(tb.Tag)).ToArray(); PlzOrtInputs = PlzInputs.Select(tb => ControlUtils.FindNextSibling(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); diff --git a/Elwig/Windows/AreaComAdminWindow.xaml b/Elwig/Windows/AreaComAdminWindow.xaml index 9369c76..b3df4ab 100644 --- a/Elwig/Windows/AreaComAdminWindow.xaml +++ b/Elwig/Windows/AreaComAdminWindow.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:Elwig.Windows" xmlns:ctrl="clr-namespace:Elwig.Controls" mc:Ignorable="d" - xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" Title="Flächenbindungen - Elwig" Height="500" MinHeight="440" Width="920" MinWidth="860" Loaded="Window_Loaded"> @@ -41,13 +40,6 @@ - -