TreeView has some quirks with selection when SelectionMode is set to Multiple when adding items to the SelectedItems collection:
You'd think that the individual TreeViewItem.IsSelected properties are set to true but they're not.
The SelectionChanged event is not fired.
Expected behavior
The 3 selection points of the TreeView should all be synced, and the SelectionChanged should be raised once (not less but not more) for any selection change to any one of them.
SelectedItem/SelectedItems
SelectedNode/SelectedNodes
TreeViewItem.IsSelected
How to reproduce it (as minimally and precisely as possible)
Current behavior
TreeView has some quirks with selection when
SelectionMode
is set toMultiple
when adding items to theSelectedItems
collection:TreeViewItem.IsSelected
properties are set to true but they're not.SelectionChanged
event is not fired.Expected behavior
The 3 selection points of the
TreeView
should all be synced, and theSelectionChanged
should be raised once (not less but not more) for any selection change to any one of them.How to reproduce it (as minimally and precisely as possible)
https://github.com/weitzhandler/TreeViewSelectionRepro
Workaround
Traverse entire tree and explicitly set each TreeViewItem.IsSelection individually to desired selection value.
Works on UWP/WinUI
No
Environment
No response
NuGet package version(s)
No response
Affected platforms
No response
IDE
No response
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
This is a WinUI issue and has been reported there as well:
https://github.com/microsoft/microsoft-ui-xaml/issues/125 https://github.com/microsoft/microsoft-ui-xaml/issues/5738