mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
fix for argument out of range exception (#6269)
This commit is contained in:
@@ -15,6 +15,7 @@ using PowerLauncher.Helper;
|
|||||||
using PowerLauncher.ViewModel;
|
using PowerLauncher.ViewModel;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
|
using Log = Wox.Infrastructure.Logger.Log;
|
||||||
using Screen = System.Windows.Forms.Screen;
|
using Screen = System.Windows.Forms.Screen;
|
||||||
|
|
||||||
namespace PowerLauncher
|
namespace PowerLauncher
|
||||||
@@ -301,9 +302,22 @@ namespace PowerLauncher
|
|||||||
ListView listview = (ListView)sender;
|
ListView listview = (ListView)sender;
|
||||||
_viewModel.Results.SelectedItem = (ResultViewModel)listview.SelectedItem;
|
_viewModel.Results.SelectedItem = (ResultViewModel)listview.SelectedItem;
|
||||||
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
listview.ScrollIntoView(e.AddedItems[0]);
|
listview.ScrollIntoView(e.AddedItems[0]);
|
||||||
}
|
}
|
||||||
|
catch (ArgumentOutOfRangeException ex)
|
||||||
|
{
|
||||||
|
// Due to virtualization being enabled for the listview, the layout system updates elements in a deferred manner using an algorithm that balances performance and concurrency.
|
||||||
|
// Hence, there can be a situation where the element index that we want to scroll into view is out of range for it's parent control.
|
||||||
|
// To mitigate this we use the UpdateLayout function, which forces layout update to ensure that the parent element contains the latest properties.
|
||||||
|
// However, it has a performance impact and is therefore not called each time.
|
||||||
|
Log.Exception("MainWindow", "The parent element layout is not updated yet", ex, "SuggestionsList_SelectionChanged");
|
||||||
|
listview.UpdateLayout();
|
||||||
|
listview.ScrollIntoView(e.AddedItems[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// To populate the AutoCompleteTextBox as soon as the selection is changed or set.
|
// To populate the AutoCompleteTextBox as soon as the selection is changed or set.
|
||||||
// Setting it here instead of when the text is changed as there is a delay in executing the query and populating the result
|
// Setting it here instead of when the text is changed as there is a delay in executing the query and populating the result
|
||||||
|
|||||||
Reference in New Issue
Block a user