From 63625a1cee1920c24e1d8e88265c2d4cfb754432 Mon Sep 17 00:00:00 2001 From: Fefe_du_973 <80718477+Fefedu973@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:06:12 +0200 Subject: [PATCH] [ColorPicker]Fixed Scrolling through the history in the color picker editor with a mouse wheel (#33551) ## Summary of the Pull Request Fixed Scrolling through the history in the color picker editor with a mouse wheel ## Detailed Description of the Pull Request / Additional comments I added a mousewheel event listener on the HistoryColors ListView, then I added two functions in the ColorEditorView.xaml.cs to handle the Event, it checks the number of color in the history and handles the scroll control accordingly --- .../ColorPickerUI/Views/ColorEditorView.xaml | 1 + .../Views/ColorEditorView.xaml.cs | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml index 490618f5d6..269805aec9 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml @@ -48,6 +48,7 @@ AutomationProperties.Name="{x:Static p:Resources.Color_History}" ItemsSource="{Binding ColorsHistory}" KeyboardNavigation.DirectionalNavigation="Contained" + MouseWheel="HistoryColors_OnMouseWheelScroll" ScrollViewer.HorizontalScrollBarVisibility="Auto" SelectedIndex="{Binding SelectedColorIndex}" SelectionMode="Extended" diff --git a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml.cs b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml.cs index 3d026a0276..a8ef6723e9 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.Windows; using System.Windows.Controls; +using System.Windows.Media; using ColorPicker.Helpers; using ColorPicker.ViewModels; @@ -42,6 +43,60 @@ namespace ColorPicker.Views }; } + /// + /// Handles the mouse wheel scroll event on the HistoryColors ListView. + /// Scrolls the ListView horizontally based on the direction of the mouse wheel scroll. + /// + /// The source of the event. + /// The mouse wheel event data. + private void HistoryColors_OnMouseWheelScroll(object sender, System.Windows.Input.MouseWheelEventArgs e) + { + var scrollViewer = FindVisualChild(HistoryColors); + + if (scrollViewer != null) + { + if (e.Delta > 0) + { + scrollViewer.LineLeft(); + } + else + { + scrollViewer.LineRight(); + } + + e.Handled = true; + } + } + + /// + /// Finds a visual child of a specified type within a given dependency object. + /// + /// The type of the child element to find. + /// The parent dependency object. + /// The first child element of the specified type, or null if no such element is found. + private static T FindVisualChild(DependencyObject obj) + where T : DependencyObject + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) + { + DependencyObject child = VisualTreeHelper.GetChild(obj, i); + if (child != null && child is T tChild) + { + return tChild; + } + else + { + T childOfChild = FindVisualChild(child); + if (childOfChild != null) + { + return childOfChild; + } + } + } + + return null; + } + /* private void HistoryColors_ItemClick(object sender, ItemClickEventArgs e) {