diff --git a/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs b/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs index 706468d..7054266 100644 --- a/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs +++ b/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs @@ -42,10 +42,25 @@ private void UserControl_OnLoaded(object? sender, RoutedEventArgs args) private void WhitelistedApplicationsListBox_OnSelectionChanged( object? sender, SelectionChangedEventArgs args - ) => - DataContext.WhitelistedApplications = WhitelistedApplicationsListBox + ) + { + var applications = WhitelistedApplicationsListBox .SelectedItems?.Cast() .ToArray(); + // Don't update the view model if the list hasn't changed. + // This is important to avoid potential infinite loops. + if ( + applications is not null + && DataContext.WhitelistedApplications is not null + && applications.SequenceEqual(DataContext.WhitelistedApplications) + ) + { + return; + } + + DataContext.WhitelistedApplications = applications; + } + public void Dispose() => _eventRoot.Dispose(); }