Преглед изворни кода

Fixto DynamicSelectionGrid refreshing too often. Added option to change selection brushes for DYnamicGrid

Kenric Nugteren пре 1 година
родитељ
комит
671badd5ef

+ 7 - 1
inabox.wpf/DynamicGrid/DynamicSelectorGrid.cs

@@ -17,6 +17,8 @@ public class DynamicSelectorGrid<T> : DynamicDataGrid<T>
 
     public HashSet<Guid> SelectedIDs { get; set; } = new();
 
+    private HashSet<Guid> LastVisible = new();
+
     public delegate void SelectionChangedEvent(HashSet<Guid> selected);
     public event SelectionChangedEvent? SelectionChanged;
 
@@ -61,7 +63,11 @@ public class DynamicSelectorGrid<T> : DynamicDataGrid<T>
     private void DoSelectionChanged()
     {
         var ids = SelectedIDs.Intersect(FilteredGuids).ToHashSet();
-        SelectionChanged?.Invoke(ids);
+        if(ids.Count != LastVisible.Count || ids.Any(x => !LastVisible.Contains(x)))
+        {
+            LastVisible = ids;
+            SelectionChanged?.Invoke(LastVisible);
+        }
     }
 
     private bool Selected_Click(CoreRow? row)

+ 6 - 4
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -115,8 +115,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         DataGrid.Background = new SolidColorBrush(Colors.DimGray);
         DataGrid.AutoGenerateColumns = false;
         DataGrid.ColumnSizer = GridLengthUnitType.AutoLastColumnFill;
-        DataGrid.SelectionForegroundBrush = DynamicGridUtils.SelectionForeground;
-        DataGrid.RowSelectionBrush = DynamicGridUtils.SelectionBackground;
+        DataGrid.SelectionForegroundBrush = GetCellSelectionForegroundBrush() ?? DynamicGridUtils.SelectionForeground;
+        DataGrid.RowSelectionBrush =  GetCellSelectionBackgroundBrush() ?? DynamicGridUtils.SelectionBackground;
         
         DataGrid.AllowDraggingRows = false;
         DataGrid.Drop += DataGrid_Drop;
@@ -571,6 +571,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         DataGrid.ScrollInView(new RowColumnIndex(rowIdx, 0));
     }
 
+    protected virtual Brush? GetCellSelectionForegroundBrush() => DynamicGridUtils.SelectionForeground;
+    protected virtual Brush? GetCellSelectionBackgroundBrush() => DynamicGridUtils.SelectionBackground;
     protected virtual Brush? GetCellBackground(CoreRow row, DynamicColumnBase column) => null;
     protected virtual Brush? GetCellForeground(CoreRow row, DynamicColumnBase column) => null;
     protected virtual double? GetCellFontSize(CoreRow row, DynamicColumnBase column) => null;
@@ -1091,8 +1093,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
     public void BeforeRefresh()
     {
-        DataGrid.SelectionForegroundBrush = DynamicGridUtils.SelectionForeground;
-        DataGrid.RowSelectionBrush = DynamicGridUtils.SelectionBackground;
+        DataGrid.SelectionForegroundBrush = GetCellSelectionForegroundBrush();
+        DataGrid.RowSelectionBrush = GetCellSelectionBackgroundBrush();
     }
 
     public void RefreshData(CoreTable data)