Switch focus to last Image Size ListViewItem on adding new size (#7505)

This commit is contained in:
Arjun Balgovind
2020-10-26 11:06:35 -07:00
committed by GitHub
parent 129342edff
commit ec22bc40bc
3 changed files with 21 additions and 1 deletions

View File

@@ -86,6 +86,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private bool _keepDateModified; private bool _keepDateModified;
private int _encoderGuidId; private int _encoderGuidId;
public bool IsListViewFocusRequested { get; set; }
public bool IsEnabled public bool IsEnabled
{ {
get get
@@ -257,6 +259,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
imageSizes.Add(newSize); imageSizes.Add(newSize);
_advancedSizes = imageSizes; _advancedSizes = imageSizes;
SavesImageSizes(imageSizes); SavesImageSizes(imageSizes);
// Set the focus requested flag to indicate that an add operation has occurred during the ContainerContentChanging event
IsListViewFocusRequested = true;
} }
public void DeleteImageSize(int id) public void DeleteImageSize(int id)

View File

@@ -65,7 +65,8 @@
SelectionMode="None" SelectionMode="None"
ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.IsHorizontalRailEnabled="True"> ScrollViewer.IsHorizontalRailEnabled="True"
ContainerContentChanging="ImagesSizesListView_ContainerContentChanging">
<ListView.ItemContainerStyle> <ListView.ItemContainerStyle>
<Style TargetType="ListViewItem"> <Style TargetType="ListViewItem">

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Linq;
using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels; using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
@@ -45,5 +46,18 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
} }
} }
private void ImagesSizesListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (ViewModel.IsListViewFocusRequested)
{
// Set focus to the last item in the ListView
int size = ImagesSizesListView.Items.Count;
((ListViewItem)ImagesSizesListView.ContainerFromIndex(size - 1)).Focus(FocusState.Programmatic);
// Reset the focus requested flag
ViewModel.IsListViewFocusRequested = false;
}
}
} }
} }