Describe the bug
TreeViewItem.IsExpanded with {x:Bind ..., Mode=TwoWay} does not work when used inside a TreeView.ItemTemplate. The binding from ViewModel → View is ignored — programmatically setting the bound property does not always expand/collapse the tree node.
The issue is likely related to virtualization — when items are recycled, the IsExpanded state from the ViewModel is not applied to the newly materialized TreeViewItem.
Why is this important?
I'm building a client application that displays file diffs in a hierarchical tree structure (folders → files → diff content). Users need to expand/collapse tree nodes both manually and programmatically (e.g. "Expand All" / "Collapse All" buttons).
Steps to reproduce the bug
- Create a
TreeView with a hierarchical ItemTemplate
- Inside the
DataTemplate, place a TreeViewItem with IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}"
- The ViewModel property implements
INotifyPropertyChanged
- Set
IsExpanded = true on a ViewModel item programmatically
- Observe that the tree nodes do not expand
<TreeView ItemsSource="{x:Bind Items,Mode=OneWay}">
<TreeView.ItemTemplate>
<DataTemplate x:DataType="vm:TreeItemViewModel">
<TreeViewItem ItemsSource="{x:Bind Items}"
IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}">
<TextBlock Text="{x:Bind Name}"/>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Actual behavior
The IsExpanded binding from ViewModel → View has sometimes no effect. The tree nodes do not expand/collapse reliable when the bound property changes.
Expected behavior
Setting IsExpanded = true on the ViewModel should expand the corresponding TreeViewItem, and collapsing a node in the UI should set the ViewModel property to false.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
Windows version
Windows 11 (24H2): Build 26100
Additional context
No response
Describe the bug
TreeViewItem.IsExpandedwith{x:Bind ..., Mode=TwoWay}does not work when used inside aTreeView.ItemTemplate. The binding from ViewModel → View is ignored — programmatically setting the bound property does not always expand/collapse the tree node.The issue is likely related to virtualization — when items are recycled, the
IsExpandedstate from the ViewModel is not applied to the newly materializedTreeViewItem.Why is this important?
I'm building a client application that displays file diffs in a hierarchical tree structure (folders → files → diff content). Users need to expand/collapse tree nodes both manually and programmatically (e.g. "Expand All" / "Collapse All" buttons).
Steps to reproduce the bug
TreeViewwith a hierarchicalItemTemplateDataTemplate, place aTreeViewItemwithIsExpanded="{x:Bind IsExpanded, Mode=TwoWay}"INotifyPropertyChangedIsExpanded = trueon a ViewModel item programmaticallyActual behavior
The IsExpanded binding from ViewModel → View has sometimes no effect. The tree nodes do not expand/collapse reliable when the bound property changes.
Expected behavior
Setting IsExpanded = true on the ViewModel should expand the corresponding TreeViewItem, and collapsing a node in the UI should set the ViewModel property to false.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
Windows version
Windows 11 (24H2): Build 26100
Additional context
No response