Repository navigation
Implement IExpandCollapseProvider on TreeViewItemAutomationPeer - #22565
Merged
Merged
Conversation
A tree item couldn't report whether it was expanded, and couldn't be expanded or collapsed through accessibility APIs. Expand and Collapse set IsExpanded, and throw for an item with no children, as WPF does. ExpandCollapseState is LeafNode when the item has no children. A change to IsExpanded or to the item count raises a property-changed event when the state changes. Fixes #22460 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GK2AhwrPmuRp98cikjR2Sk
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Reentrant child updates can produce incorrect state notifications, and Linux accessibility mappings expose invalid expansion actions for leaf items.
2 open issues
What changed in this PR
Adds expand/collapse automation support to tree items, addressing #22460 so accessibility clients can query and change their expansion state.
Changes:
- Implements expansion, collapse, and leaf-state reporting with disabled-item checks.
- Preserves bindings through
SetCurrentValueand emits state-change notifications. - Adds unit tests for states, operations, exceptions, and notifications.
| File | Description |
|---|---|
| tests/Avalonia.Controls.UnitTests/Automation/TreeViewItemAutomationPeerTests.cs | Tests expand/collapse behavior and automation notifications. |
| src/Avalonia.Controls/Automation/Peers/TreeViewItemAutomationPeer.cs | Implements the expand/collapse provider and state-change reporting. |
Review effort: Balanced
NuGet packagesThe packages for this pull request have been published (workflow run):
|
The Expanded/Collapsed routed events are raised before the peer's PropertyChanged handler runs, so a handler that populates children caused an ItemCount notification followed by a second, incorrect Collapsed -> Expanded notification. Track the last reported state and compare against it instead of the event's old/new values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ndcollapse-peer # Conflicts: # tests/Avalonia.Controls.UnitTests/Automation/TreeViewItemAutomationPeerTests.cs
MrJul
approved these changes
Oct 28, 2026
MrJul
enabled auto-merge
October 28, 2026 15:17
MrJul
pushed a commit
that referenced
this pull request
Nov 2, 2026
* Implement IExpandCollapseProvider on TreeViewItemAutomationPeer A tree item couldn't report whether it was expanded, and couldn't be expanded or collapsed through accessibility APIs. Expand and Collapse set IsExpanded, and throw for an item with no children, as WPF does. ExpandCollapseState is LeafNode when the item has no children. A change to IsExpanded or to the item count raises a property-changed event when the state changes. Fixes #22460 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GK2AhwrPmuRp98cikjR2Sk * Avoid duplicate expand/collapse notifications on reentrant changes The Expanded/Collapsed routed events are raised before the peer's PropertyChanged handler runs, so a handler that populates children caused an ItemCount notification followed by a second, incorrect Collapsed -> Expanded notification. Track the last reported state and compare against it instead of the event's old/new values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does the pull request do?
Implements
IExpandCollapseProvideronTreeViewItemAutomationPeer. A tree item can now report whether it's expanded, and can be expanded or collapsed through accessibility APIs.What is the current behavior?
The peer implements only
ISelectionItemProvider. A screen reader can't tell whether a node has hidden children. An automated test can only expand a node by clicking its toggle with synthesized input.What is the updated/expected behavior with this PR?
Expand()andCollapse()setIsExpanded.ExpandCollapseStateisExpandedorCollapsedfromIsExpanded, andLeafNodefor an item with no children.Expand()andCollapse()throwInvalidOperationExceptionon a leaf item, as WPF does. They throwElementNotEnabledExceptionwhen the item is disabled.IsExpanded, and children being added or removed (e.g.LeafNode→Expanded).How was the solution implemented (if it's not obvious)?
Expand()andCollapse()useSetCurrentValuerather than a plain setter. A common MVVM pattern bindsIsExpandedfrom a style:A plain setter would set a local value. That would shadow the style binding for good, so the item would stop following its view model.
TreeViewItem's own keyboard and pointer handling already usesSetCurrentValuefor the same reason.Checklist
Fixed issues
Fixes #22460
🤖 Generated with Claude Code
https://claude.ai/code/session_01GK2AhwrPmuRp98cikjR2Sk