bugfix dropdown closing by ESC

This commit is contained in:
Meik
2026-02-20 16:15:28 +01:00
parent 234eacaecf
commit e154353af8
9 changed files with 86 additions and 235 deletions

View File

@@ -167,7 +167,9 @@
<Border Background="{DynamicResource BackgroundColor.DetailsPage.Widget.Title}"
CornerRadius="7.5"
Width="{Binding ElementName=TicketSelectionBorder, Path=ActualWidth}">
<StackPanel x:Name="TicketSelectionContainer" />
<StackPanel x:Name="TicketSelectionContainer"
Focusable="True"
PreviewKeyDown="TicketSelectionContainer_PreviewKeyDown" />
</Border>
</Popup>
</StackPanel>

View File

@@ -2541,6 +2541,14 @@ namespace FasdDesktopUi.Basics.UserControls
DropDownOpened(TicketSelectionBorder, EventArgs.Empty);
TicketSelectionPopUp.IsOpen = !TicketSelectionPopUp.IsOpen;
if (TicketSelectionPopUp.IsOpen)
{
_ = Dispatcher.BeginInvoke((Action)(() =>
{
TicketSelectionContainer?.Focus();
Keyboard.Focus(TicketSelectionContainer);
}), System.Windows.Threading.DispatcherPriority.Input);
}
});
}
@@ -2554,6 +2562,15 @@ namespace FasdDesktopUi.Basics.UserControls
TicketSelectionBorder_Click();
}
private void TicketSelectionContainer_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Escape || TicketSelectionPopUp?.IsOpen != true)
return;
TicketSelectionPopUp.IsOpen = false;
e.Handled = true;
}
private void TicketSummaryTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
try
@@ -2665,48 +2682,6 @@ namespace FasdDesktopUi.Basics.UserControls
#region DropDown
private static bool IsInsidePageable(FrameworkElement fe) => cUiElementHelper.GetFirstParentOfType<ComboBoxPageable>(fe) != null;
public bool TryHandleEscapeKey()
{
try
{
if (TicketSelectionPopUp?.IsOpen == true)
{
TicketSelectionPopUp.IsOpen = false;
return true;
}
if (QuickTicketSelection?.IsDropDownOpen == true)
{
QuickTicketSelection.IsDropDownOpen = false;
return true;
}
if (CategorySelectionControl?.CloseDropDownIfOpen() == true)
return true;
if (ComputerSelection?.IsDropDownOpen == true)
{
ComputerSelection.IsDropDownOpen = false;
return true;
}
if (ServiceSelectionControl?.CloseDropDownIfOpen() == true)
return true;
if (TicketStatusCombobox?.IsDropDownOpen == true)
{
TicketStatusCombobox.IsDropDownOpen = false;
return true;
}
}
catch (Exception E)
{
LogException(E);
}
return false;
}
private void DropDownOpened(object sender, EventArgs e)
{
if (!(sender is FrameworkElement fe)) return;
@@ -2834,10 +2809,26 @@ namespace FasdDesktopUi.Basics.UserControls
private void Combobox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
if (e.Key != Key.Escape)
return;
if (sender is ComboBoxPageable pageable && pageable.CloseDropDownIfOpen())
{
if (sender is FrameworkElement fe && IsInsidePageable(fe)) return;
DropDownClosed(sender, e);
e.Handled = true;
return;
}
if (sender is HierarchicalSelectionControl hierarchicalSelectionControl && hierarchicalSelectionControl.CloseDropDownIfOpen())
{
e.Handled = true;
return;
}
if (sender is ComboBox comboBox && comboBox.IsDropDownOpen)
{
comboBox.IsDropDownOpen = false;
e.Handled = true;
return;
}
}
}