mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-30 14:07:42 +00:00
[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
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
AutomationProperties.Name="{x:Static p:Resources.Color_History}"
|
AutomationProperties.Name="{x:Static p:Resources.Color_History}"
|
||||||
ItemsSource="{Binding ColorsHistory}"
|
ItemsSource="{Binding ColorsHistory}"
|
||||||
KeyboardNavigation.DirectionalNavigation="Contained"
|
KeyboardNavigation.DirectionalNavigation="Contained"
|
||||||
|
MouseWheel="HistoryColors_OnMouseWheelScroll"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||||
SelectedIndex="{Binding SelectedColorIndex}"
|
SelectedIndex="{Binding SelectedColorIndex}"
|
||||||
SelectionMode="Extended"
|
SelectionMode="Extended"
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
using ColorPicker.Helpers;
|
using ColorPicker.Helpers;
|
||||||
using ColorPicker.ViewModels;
|
using ColorPicker.ViewModels;
|
||||||
|
|
||||||
@@ -42,6 +43,60 @@ namespace ColorPicker.Views
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the mouse wheel scroll event on the HistoryColors ListView.
|
||||||
|
/// Scrolls the ListView horizontally based on the direction of the mouse wheel scroll.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The source of the event.</param>
|
||||||
|
/// <param name="e">The mouse wheel event data.</param>
|
||||||
|
private void HistoryColors_OnMouseWheelScroll(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
||||||
|
{
|
||||||
|
var scrollViewer = FindVisualChild<ScrollViewer>(HistoryColors);
|
||||||
|
|
||||||
|
if (scrollViewer != null)
|
||||||
|
{
|
||||||
|
if (e.Delta > 0)
|
||||||
|
{
|
||||||
|
scrollViewer.LineLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollViewer.LineRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds a visual child of a specified type within a given dependency object.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the child element to find.</typeparam>
|
||||||
|
/// <param name="obj">The parent dependency object.</param>
|
||||||
|
/// <returns>The first child element of the specified type, or null if no such element is found.</returns>
|
||||||
|
private static T FindVisualChild<T>(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<T>(child);
|
||||||
|
if (childOfChild != null)
|
||||||
|
{
|
||||||
|
return childOfChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private void HistoryColors_ItemClick(object sender, ItemClickEventArgs e)
|
private void HistoryColors_ItemClick(object sender, ItemClickEventArgs e)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user