@@ -60,9 +60,12 @@ private void OnTrackViewPropertyChanged(object? sender, System.ComponentModel.Pr
6060 }
6161 }
6262
63- public BindableCollection < MidiFile > FilteredTracks => string . IsNullOrWhiteSpace ( FilterText )
64- ? Tracks
65- : new ( Tracks . Where ( t => t . Title . Contains ( FilterText , StringComparison . OrdinalIgnoreCase ) ) ) ;
63+ private BindableCollection < MidiFile > _filteredTracks = new ( ) ;
64+ public BindableCollection < MidiFile > FilteredTracks
65+ {
66+ get => _filteredTracks ;
67+ private set => SetAndNotify ( ref _filteredTracks , value ) ;
68+ }
6669
6770 public BindableCollection < MidiFile > Tracks { get ; } = new ( ) ;
6871
@@ -184,12 +187,12 @@ public async void PlayPauseFromQueue(MidiFile? file)
184187 public void ClearQueue ( )
185188 {
186189 Tracks . Clear ( ) ;
187- FilteredTracks . Clear ( ) ;
188190 History . Clear ( ) ;
189191
190192 OpenedFile = null ;
191193 SelectedFile = null ;
192194 SaveQueue ( ) ;
195+ ApplyFilter ( ) ;
193196 }
194197
195198 public void RemoveTrack ( )
@@ -359,6 +362,7 @@ public void RestoreQueue(IEnumerable<MidiFile> availableTracks)
359362 ShuffledTracks = new ( Tracks . OrderBy ( _ => Guid . NewGuid ( ) ) ) ;
360363
361364 RefreshQueue ( ) ;
365+ ApplyFilter ( ) ;
362366 }
363367
364368 /// <summary>
@@ -431,6 +435,7 @@ public void OnQueueModified()
431435 {
432436 SaveQueue ( ) ;
433437 RefreshQueue ( ) ;
438+ ApplyFilter ( ) ;
434439 }
435440
436441 private void RefreshQueue ( )
@@ -442,15 +447,40 @@ private void RefreshQueue()
442447 }
443448 }
444449
450+ /// <summary>
451+ /// Apply filter to create a new FilteredTracks collection
452+ /// </summary>
453+ public void ApplyFilter ( )
454+ {
455+ IEnumerable < MidiFile > filtered = string . IsNullOrWhiteSpace ( FilterText )
456+ ? Tracks
457+ : Tracks . Where ( t => t . Title . Contains ( FilterText , StringComparison . OrdinalIgnoreCase ) ) ;
458+
459+ FilteredTracks = new BindableCollection < MidiFile > ( filtered ) ;
460+ }
461+
462+ /// <summary>
463+ /// Called by PropertyChanged.Fody when FilterText changes
464+ /// </summary>
465+ private void OnFilterTextChanged ( ) => ApplyFilter ( ) ;
466+
445467 /// <summary>
446468 /// Refresh the currently playing song in the list to reflect property changes
447469 /// </summary>
448470 public void RefreshCurrentSong ( )
449471 {
450- // Force UI to refresh by notifying FilteredTracks changed
472+ // Force UI to refresh by recreating the filtered collection
473+ // This ensures the ListView re-renders items when Song properties change
451474 System . Windows . Application . Current ? . Dispatcher ? . BeginInvoke ( ( ) =>
452475 {
453- NotifyOfPropertyChange ( nameof ( FilteredTracks ) ) ;
476+ ApplyFilter ( ) ;
454477 } ) ;
455478 }
479+
480+ protected override void OnDeactivate ( )
481+ {
482+ base . OnDeactivate ( ) ;
483+ // Clear the semi-active (single-clicked) row when switching tabs
484+ SelectedFile = null ;
485+ }
456486}
0 commit comments