@@ -255,7 +255,7 @@ private void OnItemPropertyChanged(object? item, PropertyChangedEventArgs e)
255255 return ;
256256 }
257257
258- if ( FilterDescriptions . Any ( fd => string . IsNullOrEmpty ( fd . PropertyName ) || fd . PropertyName == e . PropertyName ) )
258+ if ( ! BypassFilter && FilterDescriptions . Any ( fd => string . IsNullOrEmpty ( fd . PropertyName ) || fd . PropertyName == e . PropertyName ) )
259259 {
260260 var filterResult = FilterDescriptions . All ( x => x . Predicate ( item ) ) ;
261261 var viewIndex = _view . IndexOf ( item ) ;
@@ -318,7 +318,7 @@ private void HandleSourceChanged()
318318
319319 if ( Source is not null )
320320 {
321- if ( FilterDescriptions . Count > 0 )
321+ if ( ! BypassFilter && FilterDescriptions . Count > 0 )
322322 {
323323 foreach ( var item in Source )
324324 {
@@ -331,7 +331,7 @@ private void HandleSourceChanged()
331331 _view . AddRange ( _source . OfType < object > ( ) ) ;
332332 }
333333
334- if ( SortDescriptions . Count > 0 )
334+ if ( SortDescriptions . Count > 0 && ! BypassSort )
335335 _view . Sort ( this ) ;
336336 }
337337
@@ -344,6 +344,8 @@ private void HandleSourceChanged()
344344 /// </summary>
345345 private void HandleFilterChanged ( )
346346 {
347+ if ( BypassFilter ) return ;
348+
347349 if ( FilterDescriptions . Count > 0 )
348350 {
349351 for ( var index = 0 ; index < _view . Count ; index ++ )
@@ -384,24 +386,26 @@ private void HandleFilterChanged()
384386 /// </summary>
385387 private void HandleSortChanged ( )
386388 {
387- if ( SortDescriptions . Count > 0 )
389+ if ( ! BypassSort )
388390 {
389- _view . Sort ( this ) ;
390- }
391- else
392- {
393- HandleSourceChanged ( ) ;
394- }
391+ if ( SortDescriptions . Count > 0 )
392+ _view . Sort ( this ) ;
393+ else
394+ HandleSourceChanged ( ) ;
395395
396- OnVectorChanged ( new VectorChangedEventArgs ( CollectionChange . Reset ) ) ;
396+ OnVectorChanged ( new VectorChangedEventArgs ( CollectionChange . Reset ) ) ;
397+ }
398+ // When BypassSort is true the external caller (TableView) handles the full
399+ // rebuild via RebuildHierarchyView(). Firing VectorChanged here would trigger
400+ // a stale RebuildDisplayedItems() before the hierarchy is re-flattened.
397401 }
398402
399403 /// <summary>
400404 /// Handles the addition of an item to the collection.
401405 /// </summary>
402406 private bool HandleItemAdded ( int newStartingIndex , object ? newItem , int ? viewIndex = null )
403407 {
404- if ( ! FilterDescriptions . All ( x => x . Predicate ( newItem ) ) )
408+ if ( ! BypassFilter && ! FilterDescriptions . All ( x => x . Predicate ( newItem ) ) )
405409 {
406410 return false ;
407411 }
0 commit comments