Browse Source

Fixes to header cell interaction.

Kenric Nugteren 1 year ago
parent
commit
2cf37cd628

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

@@ -1364,7 +1364,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         UIComponent.InvalidateRow(row);
     }
 
-    private void InvalidateGrid()
+    protected void InvalidateGrid()
     {
         if (RowStyleSelector != null)
             RowStyleSelector.Data = Data;

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

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 
 namespace InABox.DynamicGrid;
@@ -36,7 +37,14 @@ public class DynamicSelectorGrid<T> : DynamicDataGrid<T>
 
     private bool Selected_Click(CoreRow? row)
     {
-        if (row is null) return false;
+        if (row is null)
+        {
+            var menu = new ContextMenu();
+            menu.AddItem("Select All", null, SelectAll_Click);
+            menu.AddItem("Deselect All", null, DeselectAll_Click);
+            menu.IsOpen = true;
+            return false;
+        }
 
         var id = row.Get<T, Guid>(x => x.ID);
 
@@ -55,6 +63,20 @@ public class DynamicSelectorGrid<T> : DynamicDataGrid<T>
         return false;
     }
 
+    private void DeselectAll_Click()
+    {
+        SelectedIDs.Clear();
+        SelectionChanged?.Invoke(SelectedIDs);
+        InvalidateGrid();
+    }
+
+    private void SelectAll_Click()
+    {
+        SelectedIDs = Data.Rows.Select(x => x.Get<T, Guid>(x => x.ID)).ToHashSet();
+        SelectionChanged?.Invoke(SelectedIDs);
+        InvalidateGrid();
+    }
+
     protected override void DoReconfigure(FluentList<DynamicGridOption> options)
     {
         base.DoReconfigure(options);

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

@@ -309,12 +309,13 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         if (!DataGrid.IsEnabled)
             return;
 
+        var visualContainer = DataGrid.GetVisualContainer();
+        var rowcolumnindex = visualContainer.PointToCellRowColumnIndex(e.GetPosition(visualContainer));
+        var columnindex = DataGrid.ResolveToGridVisibleColumnIndex(rowcolumnindex.ColumnIndex);
+
         // Header Click Here!
-        if (DataGrid.SelectedIndex == -1)
+        if (rowcolumnindex.RowIndex == 0)
         {
-            var visualContainer = DataGrid.GetVisualContainer();
-            var rowcolumnindex = visualContainer.PointToCellRowColumnIndex(e.GetPosition(visualContainer));
-            var columnindex = DataGrid.ResolveToGridVisibleColumnIndex(rowcolumnindex.ColumnIndex);
 
             var column = GetColumn(columnindex);
             if(column is DynamicActionColumn dac)

+ 17 - 0
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -293,6 +293,20 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         Parent.HandleKey(e);
     }
 
+    private void HeaderCell_LeftMouseButtonEvent(object sender, MouseButtonEventArgs e)
+    {
+        if (sender is not TreeGridHeaderCell header) return;
+
+        var index = _tree.Columns.IndexOf(header.Column);
+        if (GetColumn(index) is not DynamicColumnBase column)
+            return;
+
+        if(column is DynamicActionColumn dac)
+        {
+            Parent.ExecuteActionColumn(dac, null);
+        }
+    }
+
     private void _tree_CellTapped(object? sender, TreeGridCellTappedEventArgs e)
     {
         if (!_tree.IsEnabled)
@@ -638,6 +652,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                     headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
                     headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
                     headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
+                    headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
                     if (!string.IsNullOrWhiteSpace(column.HeaderText))
                     {
                         //headstyle.Setters.Add(new Setter(LayoutTransformProperty, new RotateTransform(270.0F)));
@@ -702,6 +717,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                     headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
                     headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, -0.75, 0, 0.75)));
                     headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.75)));
+                    headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
                     if (txtCol.VerticalHeader)
                     {
                         headstyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
@@ -735,6 +751,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                     headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
                     headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, -0.75, 0, 0.75)));
                     headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.75)));
+                    headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
                     newcol.HeaderStyle = headstyle;
 
                     _tree.Columns.Add(newcol);