mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-24 04:12:32 +08:00
[ColorPicker]Scroll color history to top after choosing new color (#28291)
This commit is contained in:
parent
16e105106b
commit
ef56dcacf0
@ -2,8 +2,11 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using ColorPicker.Helpers;
|
||||
using ColorPicker.ViewModels;
|
||||
|
||||
namespace ColorPicker.Views
|
||||
{
|
||||
@ -12,8 +15,32 @@ namespace ColorPicker.Views
|
||||
/// </summary>
|
||||
public partial class ColorEditorView : UserControl
|
||||
{
|
||||
public ColorEditorView() =>
|
||||
public ColorEditorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
EnableHistoryColorsScrollIntoView();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updating SelectedColorIndex will not refresh ListView viewport.
|
||||
/// We listen for SelectedColorIndex property change and in case of a value <= 0 (new color is added) a call to ScrollIntoView is made so ListView will scroll up.
|
||||
/// </summary>
|
||||
private void EnableHistoryColorsScrollIntoView()
|
||||
{
|
||||
ColorEditorViewModel colorEditorViewModel = (ColorEditorViewModel)this.DataContext;
|
||||
((INotifyPropertyChanged)colorEditorViewModel).PropertyChanged += (sender, args) =>
|
||||
{
|
||||
if (args.PropertyName == nameof(colorEditorViewModel.SelectedColorIndex) && colorEditorViewModel.SelectedColorIndex <= 0)
|
||||
{
|
||||
HistoryColors.ScrollIntoView(colorEditorViewModel.SelectedColor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void HistoryColors_ItemClick(object sender, ModernWpf.Controls.ItemClickEventArgs e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user