diff --git a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml index bebe5a4..a1318b9 100644 --- a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml +++ b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml @@ -1,6 +1,7 @@  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs index a9abf0e..a23646d 100644 --- a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; +using static C4IT.Logging.cLogManager; namespace FasdDesktopUi.Basics.UserControls { @@ -17,6 +18,10 @@ namespace FasdDesktopUi.Basics.UserControls private readonly Dictionary itemLookup = new Dictionary(); private readonly DispatcherTimer searchDelayTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) }; private string lastSearchText = string.Empty; + + private TextBox searchTextBox; + private TreeView treeViewControl; + public ObservableCollection VisibleItems => visibleItems; public event EventHandler DropDownOpened; @@ -25,10 +30,18 @@ namespace FasdDesktopUi.Basics.UserControls public HierarchicalSelectionControl() { InitializeComponent(); - TreeViewControl.ItemsSource = visibleItems; searchDelayTimer.Tick += SearchDelayTimer_Tick; } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + EnsureTemplateParts(); + if (treeViewControl != null) + treeViewControl.ItemsSource = VisibleItems; + UpdateDisplaySelection(); + } + #region DependencyProperties public ObservableCollection ItemsSource @@ -93,16 +106,19 @@ namespace FasdDesktopUi.Basics.UserControls #endregion - private void DropDownPopup_Opened(object sender, EventArgs e) + private void ComboBoxControl_DropDownOpened(object sender, EventArgs e) { - SearchTextBox.Focus(); - SearchTextBox.SelectAll(); + EnsureTemplateParts(); + searchTextBox?.Focus(); + searchTextBox?.SelectAll(); + LogEntry($"[CategoryPicker] DropDownOpened. Selected={SelectedItem?.FullPath ?? ""}"); DropDownOpened?.Invoke(this, e); } - private void DropDownPopup_Closed(object sender, EventArgs e) + private void ComboBoxControl_DropDownClosed(object sender, EventArgs e) { searchDelayTimer.Stop(); + LogEntry("[CategoryPicker] DropDownClosed"); DropDownClosed?.Invoke(this, e); } @@ -115,7 +131,8 @@ namespace FasdDesktopUi.Basics.UserControls private void SearchDelayTimer_Tick(object sender, EventArgs e) { searchDelayTimer.Stop(); - lastSearchText = SearchTextBox.Text ?? string.Empty; + lastSearchText = searchTextBox?.Text ?? string.Empty; + LogEntry($"[CategoryPicker] Search text changed: '{lastSearchText}'"); ApplyFilter(lastSearchText); } @@ -124,10 +141,13 @@ namespace FasdDesktopUi.Basics.UserControls if (e.NewValue is HierarchicalSelectionItem selected) { var original = ResolveOriginalItem(selected); - if (original != null) + if (original != null && !Equals(SelectedItem, original)) + { SelectedItem = original; + LogEntry($"[CategoryPicker] Tree selection changed: {original.FullPath}"); + } - DropDownPopup.IsOpen = false; + ComboBoxControl.IsDropDownOpen = false; } } @@ -139,7 +159,7 @@ namespace FasdDesktopUi.Basics.UserControls if (!string.IsNullOrWhiteSpace(item.Id) && itemLookup.TryGetValue(item.Id, out var original)) return original; - return item; + return null; } private void RebuildLookup() @@ -209,13 +229,29 @@ namespace FasdDesktopUi.Basics.UserControls } } - private void DisplayBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + private void EnsureTemplateParts() { - if (!IsEnabled) - return; + if (treeViewControl == null) + { + treeViewControl = ComboBoxControl.Template.FindName("PART_TreeView", ComboBoxControl) as TreeView; + if (treeViewControl != null) + { + treeViewControl.SelectedItemChanged += TreeViewControl_SelectedItemChanged; + treeViewControl.ItemsSource = VisibleItems; + } + } - e.Handled = true; - DropDownPopup.IsOpen = !DropDownPopup.IsOpen; + if (searchTextBox == null) + { + searchTextBox = ComboBoxControl.Template.FindName("PART_SearchTextBox", ComboBoxControl) as TextBox; + if (searchTextBox != null) + searchTextBox.TextChanged += SearchTextBox_TextChanged; + } + } + + private void UpdateDisplaySelection() + { + // Display handled by ComboBox DisplayMemberPath (FullPath). } protected override void OnPreviewKeyDown(KeyEventArgs e) @@ -225,16 +261,16 @@ namespace FasdDesktopUi.Basics.UserControls if (!IsEnabled) return; - if (!DropDownPopup.IsOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space)) + if (!ComboBoxControl.IsDropDownOpen && (e.Key == Key.Enter || e.Key == Key.Down || e.Key == Key.Space)) { - DropDownPopup.IsOpen = true; + ComboBoxControl.IsDropDownOpen = true; e.Handled = true; return; } - if (DropDownPopup.IsOpen && e.Key == Key.Escape) + if (ComboBoxControl.IsDropDownOpen && e.Key == Key.Escape) { - DropDownPopup.IsOpen = false; + ComboBoxControl.IsDropDownOpen = false; e.Handled = true; } } diff --git a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml index 7401c6a..5c0adf5 100644 --- a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml +++ b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml @@ -166,6 +166,8 @@ ComboBoxBackground="{DynamicResource BackgroundColor.DetailsPage.DataHistory.ValueColumn}" BorderBrush="{DynamicResource BackgroundColor.Menu.SubCategory.Hover}" SearchPlaceholderText="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Searchbar.Placeholder}" + DropDownOpened="DropDownOpened" + DropDownClosed="DropDownClosed" PreviewKeyDown="Combobox_PreviewKeyDown" /> cUiElementHelper.GetFirstParentOfType(fe) != null; - private static bool IsHierarchicalControl(FrameworkElement fe) => fe is HierarchicalSelectionControl; private void DropDownOpened(object sender, EventArgs e) { if (!(sender is FrameworkElement fe)) return; - if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return; // Spezialfälle handeln Fokus selbst + if (IsInsidePageable(fe)) return; // ComboBoxPageable fired itself var parentBorder = cUiElementHelper.GetFirstParentOfType(fe); if (parentBorder != null) @@ -2408,7 +2407,7 @@ namespace FasdDesktopUi.Basics.UserControls private void DropDownClosed(object sender, EventArgs e) { if (!(sender is FrameworkElement fe)) return; - if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return; + if (IsInsidePageable(fe)) return; var parentBorder = cUiElementHelper.GetFirstParentOfType(fe); if (parentBorder != null)