@@ -35,7 +35,7 @@ public class TreeGrid : DataGrid
3535 private readonly object _refreshLock = new object ( ) ;
3636 private volatile bool _refreshPending = false ;
3737 private DispatcherTimer _refreshTimer ;
38- private const int REFRESH_DEBOUNCE_MS = 50 ; // Debounce delay
38+ private const int REFRESH_DEBOUNCE_MS = 20 ; // Debounce delay
3939
4040 public ICommand ExecuteCustomDescendantFilter { get ; private set ; }
4141 // Add these fields to track bound collections
@@ -571,33 +571,35 @@ private static void SynchronizeCollections(ObservableCollection<TreeGridRow<obje
571571 List < TreeGridRow < object > > source )
572572 {
573573 // Using a direct synchronization approach to minimize UI updates
574-
575- int commonLength = Math . Min ( target . Count , source . Count ) ;
576-
577- // Step 1: Update existing items that match positions
578- for ( int i = 0 ; i < commonLength ; i ++ )
574+ using ( new DeferRefresh ( target ) )
579575 {
580- if ( ! ReferenceEquals ( target [ i ] , source [ i ] ) )
576+ int commonLength = Math . Min ( target . Count , source . Count ) ;
577+
578+ // Step 1: Update existing items that match positions
579+ for ( int i = 0 ; i < commonLength ; i ++ )
581580 {
582- target [ i ] = source [ i ] ;
581+ if ( ! ReferenceEquals ( target [ i ] , source [ i ] ) )
582+ {
583+ target [ i ] = source [ i ] ;
584+ }
583585 }
584- }
585-
586- // Step 2: Remove extra items from end of target
587- if ( target . Count > source . Count )
588- {
589- for ( int i = target . Count - 1 ; i >= source . Count ; i -- )
586+
587+ // Step 2: Remove extra items from end of target
588+ if ( target . Count > source . Count )
590589 {
591- target . RemoveAt ( i ) ;
590+ for ( int i = target . Count - 1 ; i >= source . Count ; i -- )
591+ {
592+ target . RemoveAt ( i ) ;
593+ }
592594 }
593- }
594-
595- // Step 3: Add missing items to target
596- if ( source . Count > target . Count )
597- {
598- for ( int i = target . Count ; i < source . Count ; i ++ )
595+
596+ // Step 3: Add missing items to target
597+ if ( source . Count > target . Count )
599598 {
600- target . Add ( source [ i ] ) ;
599+ for ( int i = target . Count ; i < source . Count ; i ++ )
600+ {
601+ target . Add ( source [ i ] ) ;
602+ }
601603 }
602604 }
603605 }
@@ -970,10 +972,10 @@ private void SetupDefaultContextMenu()
970972 switch ( menuItem . Header . ToString ( ) )
971973 {
972974 case "Expand Selected" :
973- menuItem . IsEnabled = selectedRow ? . HasChildren == true && ! selectedRow . IsExpanded ;
975+ menuItem . IsEnabled = selectedRow ? . HasChildren == true ; // && !selectedRow.IsExpanded;
974976 break ;
975977 case "Collapse Selected" :
976- menuItem . IsEnabled = selectedRow ? . HasChildren == true && selectedRow . IsExpanded ;
978+ menuItem . IsEnabled = selectedRow ? . HasChildren == true ; // && selectedRow.IsExpanded;
977979 break ;
978980 case "Expand All" :
979981 menuItem . IsEnabled = _itemToRowMap . Values . Any ( r => r . HasChildren && ! r . IsExpanded ) ;
@@ -1186,11 +1188,11 @@ private void RemoveItemAndDescendants(object item)
11861188 private void OnChildCollectionChanged ( object parentItem , NotifyCollectionChangedEventArgs e )
11871189 {
11881190 // For UI thread safety
1189- if ( ! Dispatcher . CheckAccess ( ) )
1190- {
1191- Dispatcher . BeginInvoke ( DispatcherPriority . Normal , new Action ( ( ) => OnChildCollectionChanged ( parentItem , e ) ) ) ;
1192- return ;
1193- }
1191+ // if (!Dispatcher.CheckAccess())
1192+ // {
1193+ // Dispatcher.BeginInvoke(DispatcherPriority.Normal ,new Action(() => OnChildCollectionChanged(parentItem, e)));
1194+ // return;
1195+ // }
11941196
11951197 lock ( _refreshLock )
11961198 {
0 commit comments