diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index a77ac985aca..9e435074edb 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 { @@ -38,6 +39,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. /// @@ -331,7 +341,7 @@ public bool CanUserSort } // return whether or not the property type can be compared - return (typeof(IComparable).IsAssignableFrom(propertyType)) ? true : false; + return typeof(IComparable).IsAssignableFrom(propertyType) ? true : false; } else { @@ -810,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; @@ -911,6 +921,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; } @@ -1008,7 +1020,7 @@ internal void Resize(DataGridLength oldWidth, DataGridLength newWidth, bool user { // Recalculate star weight of this column based on the new desired value InheritsWidth = false; - newValue = (Width.Value * newDisplayValue) / ActualWidth; + newValue = Width.Value * newDisplayValue / ActualWidth; } } 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);