diff --git a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs index 7f345e48..c9ad891a 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs @@ -152,9 +152,17 @@ protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); - var delta = e.GetPosition(this) - _mouseDownPosition; + var currentPoint = e.GetCurrentPoint(this); + var delta = currentPoint.Position - _mouseDownPosition; - if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed || + var pointerSupportsDrag = currentPoint.Pointer.Type switch + { + PointerType.Mouse => currentPoint.Properties.IsLeftButtonPressed, + PointerType.Pen => currentPoint.Properties.IsRightButtonPressed, + _ => false + }; + + if (!pointerSupportsDrag || e.Handled || Math.Abs(delta.X) < DragDistance && Math.Abs(delta.Y) < DragDistance || _mouseDownPosition == s_InvalidPoint) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs index 19d709ef..4f887dbd 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs @@ -140,12 +140,19 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // Select a cell on pointer pressed if: // // - It's a mouse click, not touch: we don't want to select on touch scroll gesture start + // - It's a pen secondary button press, we don't want to select on primary button scroll gesture start // - The cell isn't already selected: we don't want to deselect an existing multiple selection // if the user is trying to drag multiple cells // // Otherwise select on pointer release. + var pointerSupportSelectionOnPress = e.Pointer.Type switch + { + PointerType.Mouse => true, + PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, + _ => false + }; if (!e.Handled && - e.Pointer.Type == PointerType.Mouse && + pointerSupportSelectionOnPress && e.Source is Control source && sender.TryGetCell(source, out var cell) && !IsSelected(cell.ColumnIndex, cell.RowIndex)) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs index ec112459..bd4da5d7 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs @@ -318,12 +318,19 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // Select a row on pointer pressed if: // // - It's a mouse click, not touch: we don't want to select on touch scroll gesture start + // - It's a pen secondary button press, we don't want to select on primary button scroll gesture start // - The row isn't already selected: we don't want to deselect an existing multiple selection // if the user is trying to drag multiple rows // // Otherwise select on pointer release. + var pointerSupportSelectionOnPress = e.Pointer.Type switch + { + PointerType.Mouse => true, + PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, + _ => false + }; if (!e.Handled && - e.Pointer.Type == PointerType.Mouse && + pointerSupportSelectionOnPress && e.Source is Control source && sender.TryGetRow(source, out var row) && _source.Rows.RowIndexToModelIndex(row.RowIndex) is { } modelIndex &&