Skip to content

Correct nested TreeViewItem selection behaviour on pointer release - #21705

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
Enscape:fixes/treeview-nestedselection
Jul 22, 2026
Merged

Correct nested TreeViewItem selection behaviour on pointer release#21705
MrJul merged 2 commits into
AvaloniaUI:mainfrom
Enscape:fixes/treeview-nestedselection

Conversation

@TomEdwardsEnscape

Copy link
Copy Markdown
Contributor

This fixes #21427, in which swiping over nested TreeViewItem containers incorrectly selects items. I found that there are actually two scenarios:

  1. Swiping from a parent to a nested item selects the parent
  2. Swiping from a nested item to a parent selects the nested item

Both a resolved. The changes can be tested with a mouse by applying this style:

<Style Selector="TreeViewItem">
  <Setter Property="InputElement.IsHoldWithMouseEnabled" Value="True"/>  
</Style>

I tried to write a unit test but found that hit testing isn't supported in the headless unit test application used by other TreeView tests.

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

Fixes #21427

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067165-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 6, 2026
@MrJul

MrJul commented Jul 6, 2026

Copy link
Copy Markdown
Member

You can use the existing CompositorTestServices to get real hit testing in unit tests.
I wanted to add them to your branch, but it's protected. See MrJul@4d75761 (disclaimer: AI authored).

@MrJul

MrJul commented Jul 6, 2026

Copy link
Copy Markdown
Member

Aside from the missing tests, it works as advertised.

@TomEdwardsEnscape

TomEdwardsEnscape commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I added the tests, but I'm not happy about having to emulate Avalonia's gesture/capture logic in the test. The mouse helper class is too low-level for this purpose.

@MrJul MrJul added backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 9, 2026
@TomEdwardsEnscape
TomEdwardsEnscape force-pushed the fixes/treeview-nestedselection branch from a3662d4 to ccfd5b3 Compare July 17, 2026 12:31
@TomEdwardsEnscape
TomEdwardsEnscape force-pushed the fixes/treeview-nestedselection branch from ccfd5b3 to 154661c Compare July 22, 2026 09:42
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067603-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 22, 2026
Merged via the queue into AvaloniaUI:main with commit d307f88 Jul 22, 2026
10 checks passed
@TomEdwardsEnscape
TomEdwardsEnscape deleted the fixes/treeview-nestedselection branch July 23, 2026 15:36
MrJul pushed a commit that referenced this pull request Jul 29, 2026
â€Ķ21705)

* Correct nested TreeViewItem selection behaviour on pointer release

* Add unit tests
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TreeViewItem is incorrectly selected after swiping onto a child item with touch/pen

3 participants