Skip to content

Feature/drag selection rectangle#344

Merged
w-ahmad merged 11 commits into
w-ahmad:mainfrom
godlytalias:feature/drag_selection_rectangle
Jun 12, 2026
Merged

Feature/drag selection rectangle#344
w-ahmad merged 11 commits into
w-ahmad:mainfrom
godlytalias:feature/drag_selection_rectangle

Conversation

@godlytalias

@godlytalias godlytalias commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Add Drag Selection Rectangle ( #334 )

Adds a semi-transparent rectangle overlay during cell/row drag selection, providing visual feedback similar to File Explorer's drag-select experience.

DragSelection.mp4

Feature Overview

  • Visual drag rectangle — A semi-transparent accent-colored rectangle follows the mouse from the drag start point to the current pointer position, clamped to the viewport. The rectangle extends naturally when content scrolls (start point adjusts for scroll offset).
  • Auto-scroll — When the pointer is near the top/bottom/left/right edges during drag, the view auto-scrolls with speed proportional to edge proximity. Vertical scroll uses a DispatcherTimer (16ms/~60fps) with ScrollViewer.ChangeView; horizontal scroll uses the existing HorizontalOffset DP pattern.
  • Scroll-sync — Selection updates for newly visible rows during auto-scroll or mouse-wheel scroll via ScrollViewer.ViewChanged handler with hit-test at the clamped pointer position.
  • ShowDragRectangle property — New bool dependency property (default: true) to enable/disable the rectangle. Setting to false mid-drag correctly tears down the rectangle. The underlying drag selection behavior (cell/row selection via pointer movement) is unaffected by this property.

Files Changed

File Change
src/TableView.Properties.cs ShowDragRectangle DP + property changed callback
src/TableView.cs Drag rectangle fields, StartDragRectangle, UpdateDragRectangleVisual, PositionDragRectangle, auto-scroll timer, ViewChanged handler, FindCellAtCanvasPoint, EndDragRectangle cleanup, OnCurrentCellChanged drag optimization, OnCellSelectionChanged coalescing, OnUnloaded cleanup
src/TableViewCell.cs OnPointerPressed starts drag, OnPointerReleased ends drag, OnPointerCaptureLost safety net, OnManipulationDelta updates rectangle visual, TransformPointToCanvas helper, ApplyCurrentCellState(skipFocus)
src/Themes/Resources.xaml Theme resources for Light, Dark, HighContrast (fill, stroke, corner radius)
src/Themes/TableView.xaml Canvas + Border overlay in control template (Grid.Row="1", IsHitTestVisible="False")
samples/.../SelectionPage.xaml ShowDragRectangle ToggleSwitch + code substitution
tests/DragSelectionRectangleTests.cs 16 unit tests covering property defaults, drag lifecycle, selection mode guards, idempotency

Lifecycle

PointerPressed → CapturePointer + StartDragRectangle (hook ViewChanged, init state)
ManipulationDelta → UpdateDragRectangleVisual (position rectangle + auto-scroll)
                  → FindCell + MakeSelection (same path as non-rectangle)
ViewChanged → PositionDragRectangle (adjust for scroll) + FindCellAtCanvasPoint + MakeSelection
PointerReleased → EndDragRectangle (stop timer, unhook events, restore focus/scroll)
PointerCaptureLost → EndDragRectangle (safety net)

Signed-off-by: Godly Alias <godlyalias@microsoft.com>
Signed-off-by: Godly Alias <godlyalias@microsoft.com>
Signed-off-by: Godly Alias <godlyalias@microsoft.com>
Signed-off-by: Godly Alias <godlyalias@microsoft.com>
Signed-off-by: Godly Alias <godlyalias@microsoft.com>
@w-ahmad

w-ahmad commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR @godlytalias, it looks great. Quick question: can we enable auto-scroll even when ShowDragRectangle is set to false? Currently the selection stops at the last visible cell without the drag rectangle.

20260410-2140-19 2165094

@godlytalias

Copy link
Copy Markdown
Contributor Author

Thanks for the PR @godlytalias, it looks great. Quick question: can we enable auto-scroll even when ShowDragRectangle is set to false? Currently the selection stops at the last visible cell without the drag rectangle.

20260410-2140-19 2165094 20260410-2140-19 2165094

@w-ahmad Sounds good, I guess we should then expose a property for devs to toggle it and have to keep it disabled by default for not breaking current behavior? We can enable the behavior only when DragSelectionRectangle being enabled? Or do you have different opinion?

@w-ahmad

w-ahmad commented Apr 12, 2026

Copy link
Copy Markdown
Owner

@w-ahmad Sounds good, I guess we should then expose a property for devs to toggle it and have to keep it disabled by default for not breaking current behavior? We can enable the behavior only when DragSelectionRectangle being enabled? Or do you have different opinion?

I think the auto-scroll must be there even when the DragSelectionRectangle is not visible and there is no need to add property to turn it on or off. This is because most DataGrid controls (tried on WPF and Synfusion) and even Excel offers it by default. The DragSelectionRectangle is a new feature for TableView, for which you’ve already added a flag property to turn it on or off.

@w-ahmad w-ahmad linked an issue Apr 12, 2026 that may be closed by this pull request
@godlytalias

Copy link
Copy Markdown
Contributor Author

@w-ahmad Sounds good, I guess we should then expose a property for devs to toggle it and have to keep it disabled by default for not breaking current behavior? We can enable the behavior only when DragSelectionRectangle being enabled? Or do you have different opinion?

I think the auto-scroll must be there even when the DragSelectionRectangle is not visible and there is no need to add property to turn it on or off. This is because most DataGrid controls (tried on WPF and Synfusion) and even Excel offers it by default. The DragSelectionRectangle is a new feature for TableView, for which you’ve already added a flag property to turn it on or off.

Okay sure, I will keep the autoscroll turned on by default then. Thanks

Signed-off-by: Godly Alias <godlyalias@microsoft.com>
Comment thread src/TableView.cs
Comment thread src/TableView.Properties.cs Outdated
Comment thread src/TableView.cs
Comment thread src/TableView.cs Outdated
Comment thread src/TableView.cs Outdated
@w-ahmad

w-ahmad commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Hey @godlytalias, just checking in on this PR. It looks quite close to being ready, and I'd love to include it in the upcoming v1.5 preview release.

Let me know if you're still planning to work on the remaining review items or if there's anything I can help with. Thanks!

@godlytalias

Copy link
Copy Markdown
Contributor Author

Hey @godlytalias, just checking in on this PR. It looks quite close to being ready, and I'd love to include it in the upcoming v1.5 preview release.

Let me know if you're still planning to work on the remaining review items or if there's anything I can help with. Thanks!

@w-ahmad I think the only pending item is to convert the internal fields as internal properties. I will update that. However I saw some discussions around this in #346, Whether some conclusion is made regarding it?

@w-ahmad

w-ahmad commented Jun 10, 2026

Copy link
Copy Markdown
Owner

@godlytalias, That discussion seems aimed at making the cells able to click thru so users can interact directly with the rows. IMO, let's stay focused on completing and merging this PR, and we can come to that feature later.

godlytalias and others added 3 commits June 12, 2026 21:10
Address PR review feedback: change the _dragRectangleCanvas and
_isDragSelecting internal fields into internal properties
(DragRectangleCanvas and IsDragSelecting) with private setters,
following the codebase convention for internal members.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflicts in src/TableView.cs (OnApplyTemplate: keep drag
rectangle template-child wiring alongside upstream's null-conditional
ScrollViewer.Loaded subscription) and src/TableView.Properties.cs
(keep both ShowDragRectangle and ForceRowOrCellSelectionOnContextRequested
properties).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread tests/DragSelectionRectangleTests.cs
godlytalias and others added 2 commits June 12, 2026 22:39
Fixes CI build break: the internal fields _isDragSelecting and
_dragRectangleCanvas were converted to internal properties
(IsDragSelecting, DragRectangleCanvas), so update the test references
accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Following the change of ShowDragRectangle's default value to true,
update the default-value assertions accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@w-ahmad w-ahmad left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
thank for your valuable contribution @godlytalias.

@w-ahmad w-ahmad merged commit 1612a18 into w-ahmad:main Jun 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drag Selection Rectangle (Rubber-Band Selection)

2 participants