mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Switch focus to last Image Size ListViewItem on adding new size (#7505)
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user