From 9cec8263c6b3f7996c33c857e6ed622dbe1423dc Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Sat, 19 Aug 2023 10:46:04 -0500 Subject: [PATCH 1/6] Added PointerPressed and PointerReleased events to the header in a DataGridColumn --- src/Avalonia.Controls.DataGrid/DataGridColumn.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index a77ac985aca..c344fe3f1bb 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs @@ -38,6 +38,15 @@ public abstract class DataGridColumn : AvaloniaObject private Classes _cellStyleClasses; private bool _setWidthInternalNoCallback; + /// + /// Occurs when the pointer is pressed over the column's header + /// + public event EventHandler HeaderPointerPressed; + /// + /// Occurs when the pointer is released over the column's header + /// + public event EventHandler HeaderPointerReleased; + /// /// Initializes a new instance of the class. /// @@ -911,6 +920,8 @@ internal virtual DataGridColumnHeader CreateHeader() result.SetValue(StyledElement.ThemeProperty, columnTheme, BindingPriority.Template); } + result.PointerPressed += (s, e) => { HeaderPointerPressed?.Invoke(this, e); }; + result.PointerReleased += (s, e) => { HeaderPointerReleased?.Invoke(this, e); }; return result; } From 638b77eff276c572df23628236b5a1fe36137ef7 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 2 Oct 2023 17:58:02 -0500 Subject: [PATCH 2/6] update refs --- .../Avalonia.Controls.DataGrid.csproj | 11 ++------ .../DataGridColumn.cs | 13 +++++----- .../DataGridColumnHeader.cs | 25 +++++++++++-------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 6c1e0196035..6e48175a8e7 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -1,20 +1,13 @@  - net6.0;netstandard2.0 + net7.0 Avalonia.Controls.DataGrid - - - - - + - - - diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index c344fe3f1bb..68157f1e0eb 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs @@ -3,19 +3,20 @@ // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. -using Avalonia.Data; -using Avalonia.Interactivity; -using Avalonia.VisualTree; -using Avalonia.Collections; using System; using System.ComponentModel; -using System.Linq; using System.Diagnostics; +using System.Linq; +using Avalonia.Collections; using Avalonia.Controls.Templates; using Avalonia.Controls.Utils; +using Avalonia.Data; +using Avalonia.Input; +using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Markup.Xaml.MarkupExtensions; using Avalonia.Styling; +using Avalonia.VisualTree; namespace Avalonia.Controls { @@ -819,7 +820,7 @@ internal void EndCellEditInternal() /// /// The DataGridLength to coerce. /// The resultant (coerced) DataGridLength. - static DataGridLength CoerceWidth(AvaloniaObject source, DataGridLength width) + private static DataGridLength CoerceWidth(AvaloniaObject source, DataGridLength width) { var target = (DataGridColumn)source; diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs index 28e8a0ed5e5..1eef700a45f 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs @@ -3,18 +3,17 @@ // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. -using Avalonia.Controls.Primitives; +using System; +using System.ComponentModel; +using System.Diagnostics; +using Avalonia.Collections; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Mixins; +using Avalonia.Controls.Utils; using Avalonia.Data; using Avalonia.Input; -using Avalonia.Collections; using Avalonia.Media; -using System.ComponentModel; -using System.Diagnostics; using Avalonia.Utilities; -using System; -using Avalonia.Controls.Utils; -using Avalonia.Controls.Mixins; -using Avalonia.Controls.Metadata; namespace Avalonia.Controls { @@ -195,8 +194,12 @@ internal void UpdateSeparatorVisibility(DataGridColumn lastVisibleColumn) } } + public event EventHandler LeftClick; + internal void OnMouseLeftButtonUp_Click(KeyModifiers keyModifiers, ref bool handled) { + LeftClick?.Invoke(this, keyModifiers); + // completed a click without dragging, so we're sorting InvokeProcessSort(keyModifiers); handled = true; @@ -441,7 +444,7 @@ internal void OnMouseMove(PointerEventArgs args, Point mousePosition, Point mous } Debug.Assert(OwningGrid.Parent is InputElement); - + OnMouseMove_Resize(ref handled, mousePositionHeaders); OnMouseMove_Reorder(ref handled, mousePosition, mousePositionHeaders); @@ -669,7 +672,7 @@ private void OnMouseMove_BeginReorder(Point mousePosition) Content = Content, ContentTemplate = ContentTemplate }; - if (OwningGrid.ColumnHeaderTheme is {} columnHeaderTheme) + if (OwningGrid.ColumnHeaderTheme is { } columnHeaderTheme) { dragIndicator.SetValue(ThemeProperty, columnHeaderTheme, BindingPriority.Template); } @@ -786,7 +789,7 @@ private void OnMouseMove_Resize(ref bool handled, Point mousePositionHeaders) desiredWidth = Math.Max(_dragColumn.ActualMinWidth, Math.Min(_dragColumn.ActualMaxWidth, desiredWidth)); _dragColumn.Resize(_dragColumn.Width, - new(_dragColumn.Width.Value, _dragColumn.Width.UnitType, _dragColumn.Width.DesiredValue, desiredWidth), + new(_dragColumn.Width.Value, _dragColumn.Width.UnitType, _dragColumn.Width.DesiredValue, desiredWidth), true); OwningGrid.UpdateHorizontalOffset(_originalHorizontalOffset); From 72f6dae313fdbaa574c9e5bfb5fdb6b4d428a701 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 23 Oct 2023 15:27:54 -0500 Subject: [PATCH 3/6] Update Avalonia.Controls.DataGrid.csproj --- .../Avalonia.Controls.DataGrid.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 6e48175a8e7..5509ff5e9ab 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -1,6 +1,6 @@  - net7.0 + net6.0;netstandard2.0 Avalonia.Controls.DataGrid From 40c80ef42ae6943fcfe75fa37142f618a93b4a66 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 2 Nov 2023 10:17:48 -0500 Subject: [PATCH 4/6] revert project file changes --- .../Avalonia.Controls.DataGrid.csproj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 7c88003ae7b..8f5a64c0992 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -3,11 +3,17 @@ net6.0;netstandard2.0 - + + + + + - + + + From cd019a69e8fb09cb82a1892040714203e6d7a915 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 2 Nov 2023 10:19:24 -0500 Subject: [PATCH 5/6] more reversion --- .../Avalonia.Controls.DataGrid.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 8f5a64c0992..070a7cd095b 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -6,14 +6,15 @@ - - + + + From afe593b82d51b468302d749ad97bda924190df3c Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 2 Nov 2023 10:20:41 -0500 Subject: [PATCH 6/6] removed spaces --- .../Avalonia.Controls.DataGrid.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 070a7cd095b..b003dcf7a46 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -14,7 +14,7 @@ - +