Kategorie

This commit is contained in:
Meik
2025-11-11 20:22:10 +01:00
parent 05fb34815a
commit 8cf1c84328
2 changed files with 14 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ using System.Windows.Threading;
namespace FasdDesktopUi.Basics.UserControls namespace FasdDesktopUi.Basics.UserControls
{ {
public partial class HierarchicalSelectionControl : UserControl, IFocusInvoker public partial class HierarchicalSelectionControl : UserControl
{ {
private readonly ObservableCollection<HierarchicalSelectionItem> visibleItems = new ObservableCollection<HierarchicalSelectionItem>(); private readonly ObservableCollection<HierarchicalSelectionItem> visibleItems = new ObservableCollection<HierarchicalSelectionItem>();
private readonly Dictionary<string, HierarchicalSelectionItem> itemLookup = new Dictionary<string, HierarchicalSelectionItem>(); private readonly Dictionary<string, HierarchicalSelectionItem> itemLookup = new Dictionary<string, HierarchicalSelectionItem>();
@@ -19,8 +19,8 @@ namespace FasdDesktopUi.Basics.UserControls
private string lastSearchText = string.Empty; private string lastSearchText = string.Empty;
public ObservableCollection<HierarchicalSelectionItem> VisibleItems => visibleItems; public ObservableCollection<HierarchicalSelectionItem> VisibleItems => visibleItems;
public int? ParentIndex { get; set; } public event EventHandler DropDownOpened;
public UIElement ParentElement { get; set; } public event EventHandler DropDownClosed;
public HierarchicalSelectionControl() public HierarchicalSelectionControl()
{ {
@@ -97,27 +97,13 @@ namespace FasdDesktopUi.Basics.UserControls
{ {
SearchTextBox.Focus(); SearchTextBox.Focus();
SearchTextBox.SelectAll(); SearchTextBox.SelectAll();
EnsureParentPlacement(); DropDownOpened?.Invoke(this, e);
cFocusInvoker.InvokeGotFocus(this, e);
} }
private void DropDownPopup_Closed(object sender, EventArgs e) private void DropDownPopup_Closed(object sender, EventArgs e)
{ {
searchDelayTimer.Stop(); searchDelayTimer.Stop();
cFocusInvoker.InvokeLostFocus(this, e); DropDownClosed?.Invoke(this, e);
}
private void EnsureParentPlacement()
{
if (ParentElement == null || ParentElement != this.Parent)
{
ParentElement = this.Parent as UIElement;
if (this.Parent is Panel panel)
ParentIndex = panel.Children.IndexOf(this);
else
ParentIndex = null;
}
} }
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)

View File

@@ -2392,25 +2392,23 @@ namespace FasdDesktopUi.Basics.UserControls
#region DropDown #region DropDown
private static bool IsInsidePageable(FrameworkElement fe) private static bool IsInsidePageable(FrameworkElement fe) => cUiElementHelper.GetFirstParentOfType<ComboBoxPageable>(fe) != null;
{ private static bool IsHierarchicalControl(FrameworkElement fe) => fe is HierarchicalSelectionControl;
return cUiElementHelper.GetFirstParentOfType<ComboBoxPageable>(fe) != null;
}
private void DropDownOpened(object sender, EventArgs e) private void DropDownOpened(object sender, EventArgs e)
{ {
if (!(sender is FrameworkElement fe)) return; if (!(sender is FrameworkElement fe)) return;
if (IsInsidePageable(fe)) return; // ComboBoxPageable macht das selbst if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return; // Spezialfälle handeln Fokus selbst
var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe); var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe);
if (parentBorder != null) if (parentBorder != null)
cFocusInvoker.InvokeGotFocus(parentBorder, e); cFocusInvoker.InvokeGotFocus(parentBorder, e);
} }
private void DropDownClosed(object sender, EventArgs e) private void DropDownClosed(object sender, EventArgs e)
{ {
if (!(sender is FrameworkElement fe)) return; if (!(sender is FrameworkElement fe)) return;
if (IsInsidePageable(fe)) return; if (IsInsidePageable(fe) || IsHierarchicalControl(fe)) return;
var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe); var parentBorder = cUiElementHelper.GetFirstParentOfType<Border>(fe);
if (parentBorder != null) if (parentBorder != null)