From e154353af8c5fb74e9e49acad37f81ae19c11736 Mon Sep 17 00:00:00 2001 From: Meik Date: Fri, 20 Feb 2026 16:15:28 +0100 Subject: [PATCH] bugfix dropdown closing by ESC --- FasdDesktopUi/Basics/UserControls/Badge.xaml | 75 +++-------- .../Basics/UserControls/Badge.xaml.cs | 116 +----------------- .../UserControls/ComboBoxPageable.xaml.cs | 11 ++ .../HierarchicalSelectionControl.xaml.cs | 13 ++ .../Ticket/CloseCaseDialogWithTicket.xaml | 4 +- .../Ticket/CloseCaseDialogWithTicket.xaml.cs | 81 ++++++------ .../Pages/SearchPage/SearchPageView.xaml | 1 - .../TicketCompletion/TicketCompletion.xaml | 2 +- .../TicketCompletion/TicketCompletion.xaml.cs | 18 +-- 9 files changed, 86 insertions(+), 235 deletions(-) diff --git a/FasdDesktopUi/Basics/UserControls/Badge.xaml b/FasdDesktopUi/Basics/UserControls/Badge.xaml index 10b98b4..c85f5f4 100644 --- a/FasdDesktopUi/Basics/UserControls/Badge.xaml +++ b/FasdDesktopUi/Basics/UserControls/Badge.xaml @@ -3,70 +3,25 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:FasdDesktopUi.Basics.UserControls" + xmlns:ico="clr-namespace:FasdDesktopUi.Basics.UserControls.AdaptableIcon;assembly=F4SD-AdaptableIcon" mc:Ignorable="d" d:DesignHeight="20" d:DesignWidth="40" - x:Name="BadgeControl" - Loaded="BadgeControl_Loaded" - Unloaded="BadgeControl_Unloaded"> + x:Name="BadgeControl"> - - - - - - + - - - - - - - - + + + - - - - - - - - - + diff --git a/FasdDesktopUi/Basics/UserControls/Badge.xaml.cs b/FasdDesktopUi/Basics/UserControls/Badge.xaml.cs index 2eb9e0c..8c095aa 100644 --- a/FasdDesktopUi/Basics/UserControls/Badge.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/Badge.xaml.cs @@ -1,16 +1,10 @@ -using System; -using System.Windows; +using System.Windows; using System.Windows.Controls; -using System.Windows.Media; -using System.Windows.Media.Animation; namespace FasdDesktopUi.Basics.UserControls { public partial class Badge : UserControl { - private readonly Storyboard _sparkleStoryboard; - private const double SparkleBaseScale = 0.6; - public string Text { get { return (string)GetValue(TextProperty); } @@ -20,118 +14,10 @@ namespace FasdDesktopUi.Basics.UserControls public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(Badge), new PropertyMetadata("Beta")); - public bool IsSparkleEnabled - { - get { return (bool)GetValue(IsSparkleEnabledProperty); } - set { SetValue(IsSparkleEnabledProperty, value); } - } - - public static readonly DependencyProperty IsSparkleEnabledProperty = - DependencyProperty.Register(nameof(IsSparkleEnabled), typeof(bool), typeof(Badge), new PropertyMetadata(false, OnIsSparkleEnabledChanged)); - public Badge() { InitializeComponent(); - _sparkleStoryboard = CreateSparkleStoryboard(); - UpdateSparkleState(); - } - - private static void OnIsSparkleEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var control = d as Badge; - control?.UpdateSparkleState(); - } - - private void BadgeControl_Loaded(object sender, RoutedEventArgs e) - { - UpdateSparkleState(); - } - - private void BadgeControl_Unloaded(object sender, RoutedEventArgs e) - { - StopSparkles(); - } - - private void UpdateSparkleState() - { - if (SparkleCanvas == null || _sparkleStoryboard == null) - { - return; - } - - if (IsSparkleEnabled) - { - SparkleCanvas.Visibility = Visibility.Visible; - _sparkleStoryboard.Begin(this, true); - return; - } - - SparkleCanvas.Visibility = Visibility.Collapsed; - StopSparkles(); - } - - private void StopSparkles() - { - _sparkleStoryboard?.Stop(this); - - if (SparkleTopRight != null) - { - SparkleTopRight.Opacity = 0; - if (SparkleTopRight.RenderTransform is ScaleTransform topTransform) - { - topTransform.ScaleX = SparkleBaseScale; - topTransform.ScaleY = SparkleBaseScale; - } - } - - if (SparkleBottomLeft != null) - { - SparkleBottomLeft.Opacity = 0; - if (SparkleBottomLeft.RenderTransform is ScaleTransform bottomTransform) - { - bottomTransform.ScaleX = SparkleBaseScale; - bottomTransform.ScaleY = SparkleBaseScale; - } - } - } - - private Storyboard CreateSparkleStoryboard() - { - var storyboard = new Storyboard - { - RepeatBehavior = RepeatBehavior.Forever - }; - - AddKeyFrames(storyboard, SparkleTopRight, "Opacity", - (0.00, 0.0), (0.18, 1.0), (0.42, 0.0), (2.20, 0.0)); - AddKeyFrames(storyboard, SparkleTopRight, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)", - (0.00, SparkleBaseScale), (0.22, 1.15), (0.42, SparkleBaseScale), (2.20, SparkleBaseScale)); - AddKeyFrames(storyboard, SparkleTopRight, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)", - (0.00, SparkleBaseScale), (0.22, 1.15), (0.42, SparkleBaseScale), (2.20, SparkleBaseScale)); - - AddKeyFrames(storyboard, SparkleBottomLeft, "Opacity", - (0.00, 0.0), (1.00, 0.0), (1.18, 1.0), (1.42, 0.0), (2.20, 0.0)); - AddKeyFrames(storyboard, SparkleBottomLeft, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)", - (0.00, SparkleBaseScale), (1.00, SparkleBaseScale), (1.22, 1.15), (1.42, SparkleBaseScale), (2.20, SparkleBaseScale)); - AddKeyFrames(storyboard, SparkleBottomLeft, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)", - (0.00, SparkleBaseScale), (1.00, SparkleBaseScale), (1.22, 1.15), (1.42, SparkleBaseScale), (2.20, SparkleBaseScale)); - - return storyboard; - } - - private static void AddKeyFrames(Storyboard storyboard, DependencyObject target, string targetProperty, params (double TimeSeconds, double Value)[] frames) - { - var animation = new DoubleAnimationUsingKeyFrames(); - - foreach (var frame in frames) - { - animation.KeyFrames.Add(new LinearDoubleKeyFrame(frame.Value, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(frame.TimeSeconds)))); - } - - Storyboard.SetTarget(animation, target); - Storyboard.SetTargetProperty(animation, new PropertyPath(targetProperty)); - storyboard.Children.Add(animation); } } } diff --git a/FasdDesktopUi/Basics/UserControls/ComboBoxPageable.xaml.cs b/FasdDesktopUi/Basics/UserControls/ComboBoxPageable.xaml.cs index e547e4d..1b52a5d 100644 --- a/FasdDesktopUi/Basics/UserControls/ComboBoxPageable.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/ComboBoxPageable.xaml.cs @@ -325,6 +325,15 @@ namespace FasdDesktopUi.Basics.UserControls } } + private void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) + { + if (e.Key != Key.Escape) + return; + + if (CloseDropDownIfOpen()) + e.Handled = true; + } + private void ComboBoxControl_DropDownClosed(object sender, EventArgs e) { timer.Stop(); @@ -393,6 +402,8 @@ namespace FasdDesktopUi.Basics.UserControls TextBox searchTextBox = FindVisualChild(partPopup.Child, "SearchTextBox"); if (searchTextBox != null) { + searchTextBox.PreviewKeyDown -= SearchTextBox_PreviewKeyDown; + searchTextBox.PreviewKeyDown += SearchTextBox_PreviewKeyDown; // Setzen des Fokus auf TextBox searchTextBox.Focus(); } diff --git a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs index eb6b4a1..192fb18 100644 --- a/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/HierarchicalSelectionControl.xaml.cs @@ -354,6 +354,7 @@ namespace FasdDesktopUi.Basics.UserControls if (treeViewControl != null) { treeViewControl.SelectedItemChanged += TreeViewControl_SelectedItemChanged; + treeViewControl.PreviewKeyDown += DropDownContent_PreviewKeyDown; treeViewControl.ItemsSource = VisibleItems; } } @@ -362,7 +363,10 @@ namespace FasdDesktopUi.Basics.UserControls { searchTextBox = ComboBoxControl.Template.FindName("PART_SearchTextBox", ComboBoxControl) as TextBox; if (searchTextBox != null) + { searchTextBox.TextChanged += SearchTextBox_TextChanged; + searchTextBox.PreviewKeyDown += DropDownContent_PreviewKeyDown; + } } if (itemsScrollViewer == null) @@ -408,6 +412,15 @@ namespace FasdDesktopUi.Basics.UserControls e.Handled = true; } + private void DropDownContent_PreviewKeyDown(object sender, KeyEventArgs e) + { + if (e.Key != Key.Escape) + return; + + if (CloseDropDownIfOpen()) + e.Handled = true; + } + #endregion #region Keyboard diff --git a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml index 787b8d9..de44d1b 100644 --- a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml +++ b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml @@ -167,7 +167,9 @@ - + diff --git a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs index 687f1a5..4454da0 100644 --- a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs @@ -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(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; } } } diff --git a/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml b/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml index f63532e..c4a2144 100644 --- a/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml +++ b/FasdDesktopUi/Pages/SearchPage/SearchPageView.xaml @@ -120,7 +120,6 @@ FontWeight="Bold" Visibility="Visible" /> diff --git a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml index 45aa344..8cb1e65 100644 --- a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml +++ b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml @@ -18,7 +18,7 @@ Background="Transparent" WindowStartupLocation="CenterOwner" DataContext="{Binding RelativeSource={RelativeSource Self}}" - PreviewKeyDown="CustomMessageBox_PreviewKeyDown" + KeyDown="CustomMessageBox_KeyDown" IsVisibleChanged="BlurInvoker_IsActiveChanged"> diff --git a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs index 296ed42..02ba9bf 100644 --- a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs +++ b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs @@ -280,21 +280,15 @@ namespace FasdDesktopUi.Pages.TicketCompletion #endregion - private void CustomMessageBox_PreviewKeyDown(object sender, KeyEventArgs e) + private void CustomMessageBox_KeyDown(object sender, KeyEventArgs e) { - switch (e.Key) + if (e.Key != Key.Escape) { - case Key.Escape: - if (CloseCaseDialogUc?.TryHandleEscapeKey() == true) - { - e.Handled = true; - return; - } - - Close_Click(); - e.Handled = true; - break; + return; } + + Close_Click(); + e.Handled = true; } private async Task DoCloseActionAsync()