Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PointerPressed and PointerReleased events to DataGrid header #12595

Merged
merged 15 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
ctacke marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\Avalonia.Remote.Protocol\Avalonia.Remote.Protocol.csproj" />
<ProjectReference Include="..\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
<ProjectReference Include="..\Markup\Avalonia.Markup\Avalonia.Markup.csproj" />
<ProjectReference Include="..\Avalonia.Controls\Avalonia.Controls.csproj" />
<PackageReference Include="Avalonia" Version="11.0.3" />
<!-- Compatibility with old apps -->
<EmbeddedResource Include="Themes\**\*.xaml" />
</ItemGroup>
<Import Project="..\..\build\EmbedXaml.props" />
<Import Project="..\..\build\BuildTargets.targets" />
<Import Project="..\..\build\DevAnalyzers.props" />
ctacke marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup Label="InternalsVisibleTo">
<InternalsVisibleTo Include="Avalonia.Controls.DataGrid.UnitTests, PublicKey=$(AvaloniaPublicKey)" />
Expand Down
24 changes: 18 additions & 6 deletions src/Avalonia.Controls.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -38,6 +39,15 @@ public abstract class DataGridColumn : AvaloniaObject
private Classes _cellStyleClasses;
private bool _setWidthInternalNoCallback;

/// <summary>
/// Occurs when the pointer is pressed over the column's header
/// </summary>
public event EventHandler<PointerPressedEventArgs> HeaderPointerPressed;
/// <summary>
/// Occurs when the pointer is released over the column's header
/// </summary>
public event EventHandler<PointerReleasedEventArgs> HeaderPointerReleased;

/// <summary>
/// Initializes a new instance of the <see cref="T:Avalonia.Controls.DataGridColumn" /> class.
/// </summary>
Expand Down Expand Up @@ -810,7 +820,7 @@ internal void EndCellEditInternal()
/// <param name="source"></param>
/// <param name="width">The DataGridLength to coerce.</param>
/// <returns>The resultant (coerced) DataGridLength.</returns>
static DataGridLength CoerceWidth(AvaloniaObject source, DataGridLength width)
private static DataGridLength CoerceWidth(AvaloniaObject source, DataGridLength width)
{
var target = (DataGridColumn)source;

Expand Down Expand Up @@ -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;
}

Expand Down
25 changes: 14 additions & 11 deletions src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -195,8 +194,12 @@ internal void UpdateSeparatorVisibility(DataGridColumn lastVisibleColumn)
}
}

public event EventHandler<KeyModifiers> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Loading