microsoft / microsoft/microsoft-ui-xaml

Treeview - Changing root node and child node contents is not visually reflected in these nodes' displays.

Open
#10,002 1 comment 0 reactions 0 assignees View on GitHub
area-TreeView bug team-Controls
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

Changing the contents of existing root and child nodes does not update the display of the nodes.

Note that collapsing and expanding child nodes will force a refresh and the display is now correct.

### Steps to reproduce the bug

1. Add a root node to a TreeView and set its contents to "Node 0"
2. Add a child node to root node above and set it contents to "Child Node"
3. Change the contents of the root node to "New Node Name"
4. Change the contents of the child node to "New Child Name"

Problem: Root node still displays "Node 0" and child node still displays "Child Node".

Note that if you collapse and expand the child node, it will now display "New Child Name"

### Expected behavior

The display for exisiting root nodes and child nodes should be updated when their contents are updated

### Screenshots

This sample apps consists of a TextBlock on left, TreeView in middle with 3 root nodes and a child node, and a button on right to update contents of 1st root node and its child node.

![image](https://github.com/user-attachments/assets/827ef178-a917-4fb4-9515-36379c73917c)

Clicking Rename button shows that the TextBlock has read back the first root node contents and shows it to be the new content.
However, the 1st root node and its child node has not changed
![image](https://github.com/user-attachments/assets/04df8bbc-bbbb-481b-b698-4bfb977339cb)

Collapsing then expanding the 1st root node causes the child node to refresh and it now displays the new content
![image](https://github.com/user-attachments/assets/02c9edfa-8a08-45d7-b008-a4e9f9adba00)

### NuGet package version

WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007

### Windows version

Windows 10 (21H2): Build 19044

### Additional context

MainWindow.xaml




Rename

MainWindow.xaml.cs
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();

InitializeTreeView();
}

private void InitializeTreeView()
{
int iIdx;

TreeViewNode treeViewNode;
TreeViewNode treeViewChildNode;

for (iIdx = 0; iIdx < 3; ++iIdx)
{
treeViewNode = new TreeViewNode()
{
Content = "Node " + iIdx.ToString(),
};

TreeViewMain.RootNodes.Add(treeViewNode);
}

treeViewNode = TreeViewMain.RootNodes[0];

TextBlockContent.Text = treeViewNode.Content.ToString();

treeViewChildNode = new TreeViewNode()
{
Content = "Child Node ",
};

treeViewNode.Children.Add(treeViewChildNode);
}

private void UpdateRootAndChildNode()
{
TreeViewNode treeViewNode;
TreeViewNode treeViewChildNode;

treeViewNode = TreeViewMain.RootNodes[0];

treeViewNode.Content = "New Node Name";

TextBlockContent.Text = treeViewNode.Content.ToString();

treeViewChildNode = treeViewNode.Children[0];

treeViewChildNode.Content = "New Child Name";

TreeViewMain.UpdateLayout();
}

private void myButton_Click(object sender, RoutedEventArgs e)
{
UpdateRootAndChildNode();
}

Also attaching project
[TreeNodeSample.zip](https://github.com/user-attachments/files/17084204/TreeNodeSample.zip)

Contributor guide

Open the contributing guide

Research direction

Start by running the attached TreeNodeSample and reading MainWindow.xaml.cs, especially InitializeTreeView and UpdateRootAndChildNode. Trace the WinUI TreeView rendering and content-update path, then verify that changing existing root and child contents updates both displays without collapsing and expanding nodes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.