diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs index c0e78d3e87..1ba7d11227 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs @@ -63,8 +63,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views this.QuickAccent_Language_Select.DeselectAll(); } + private bool loadingLanguageListDontTriggerSelectionChanged; + private void QuickAccent_SelectedLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) { + if (loadingLanguageListDontTriggerSelectionChanged) + { + return; + } + var listView = sender as ListView; ViewModel.SelectedLanguageOptions = listView.SelectedItems @@ -76,10 +83,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views private void QuickAccent_Language_Select_Loaded(object sender, RoutedEventArgs e) { + loadingLanguageListDontTriggerSelectionChanged = true; foreach (var languageOption in ViewModel.SelectedLanguageOptions) { this.QuickAccent_Language_Select.SelectedItems.Add(languageOption); } + + loadingLanguageListDontTriggerSelectionChanged = false; } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs index 7da5c4ecfb..ca2bdabe07 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs @@ -115,6 +115,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { SelectedLanguageOptions = _powerAccentSettings.Properties.SelectedLang.Value.Split(',') .Select(l => Languages.Find(lang => lang.LanguageCode == l)) + .Where(l => l != null) // Wrongly typed languages will appear as null after find. We want to remove those to avoid crashes. .ToArray(); } else if (_powerAccentSettings.Properties.SelectedLang.Value.Contains("ALL"))