Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The selected node of TreeView will be automatic change when expand #1820

Closed
zhuxb711 opened this issue Jan 8, 2020 · 14 comments · Fixed by #2547
Closed

The selected node of TreeView will be automatic change when expand #1820

zhuxb711 opened this issue Jan 8, 2020 · 14 comments · Fixed by #2547
Labels
area-TreeView bug Something isn't working team-Controls Issue for the Controls team
Milestone

Comments

@zhuxb711
Copy link
Contributor

zhuxb711 commented Jan 8, 2020

Describe the bug

The selected item in TreeView will be automatic change when expand
Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Select a node in TreeView, which is not expanded
  2. Then expand this node, now the selected node of treeview was changed to its sub node.

Expected behavior

The selected node of TreeView should not be changed
Screenshots

GIF 2020-1-8 17-10-00

Version Info

NuGet package version:

2.3.191211002

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2019 Update (18362) Yes
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

Additional context

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Jan 8, 2020
@kmahone
Copy link
Member

kmahone commented Jan 8, 2020

@zhuxb711, thanks for reporting this issue. I was not able to reproduce the issue myself. Could you please share a repro app with us?

Could you also please clarify how you are interacting with the TreeView? Are you using mouse or keyboard?

Thanks.

@kmahone kmahone added needs-author-feedback Asked author to supply more information. area-TreeView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jan 8, 2020
@zhuxb711
Copy link
Contributor Author

zhuxb711 commented Jan 9, 2020

@kmahone I'm using mouse to interact.

I make a demo for you, this problem does exist. &If I select parent node and then expand it, the selection will be changed to its subnode.

Tips: Before you run the demo, please granting "file system access" in system setting for demo
TreeViewTest.zip

@msft-github-bot msft-github-bot added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Jan 9, 2020
@kmahone
Copy link
Member

kmahone commented Jan 9, 2020

Thanks @zhuxb711 I can reproduce the issue now.

@kmahone kmahone added bug Something isn't working and removed needs-triage Issue needs to be triaged by the area owners labels Jan 9, 2020
@kmahone
Copy link
Member

kmahone commented Jan 9, 2020

@kaiguo can you please take a look to determine the root cause here and come up with a workaround if possible.

@zhuxb711
Copy link
Contributor Author

@kmahone This problem is very confusing to my users and hopes to be fixed as soon as possible

@zhuxb711
Copy link
Contributor Author

I want to know when this problem can be fixed @kmahone

@ranjeshj
Copy link
Contributor

ranjeshj commented Mar 23, 2020

@zhub711 there have been some fixes to TreeView, can you see if the issue repros in the latest prerelease (went out today). @kaiguo did you get a chance to look at this ?

@zhuxb711
Copy link
Contributor Author

I have installed the latest preview version and tested this issue, it still exists and has not been fixed @ranjeshj

@ranjeshj
Copy link
Contributor

This is really weird behavior. I'm not sure yet why the expansion and populating of the children collection would affect the selection state. @zhuxb711 One hacky workaround to unblock you could be to save and restore the selection after the expand operation like so.

var oldSelectedNode = FolderTree.SelectedNode;
if (args.Node.HasUnrealizedChildren)
{
await FillTreeNode(args.Node);
}
FolderTree.SelectedNode = oldSelectedNode;

@zhuxb711
Copy link
Contributor Author

@ranjeshj @kaiguo But this code still looks strange. I also think that expanding a selected TreeViewNode will cause the selected item to change very strangely. Is there any progress in the investigation of the cause of this problem?

@kaiguo
Copy link
Contributor

kaiguo commented Apr 25, 2020

@ranjeshj not 100% sure but it probably has something to do with this,

if (selectionState != itemNode->SelectionState())
{
ListViewModel()->UpdateSelection(*itemNode, selectionState);
}

I think this code was added to reverse some ListView selection changes we didn't want when using databinding. The demo code works on TreeNode directly and doesn't use ItemsSource binding. Perhaps we should execute the code block above only in content mode so adding an extra IsContentMode() check might fix the issue.

@Felix-Dev
Copy link
Contributor

Felix-Dev commented Apr 26, 2020

@kaiguo You probably should test it yourself but I went ahead and added your suggestion to the TreeViewList, then built a nuget package of WinUI and used it on the repro app. Result: I'm still seeing the same erroneous selection change behavior reported here.

@zhuxb711
Copy link
Contributor Author

@kaiguo @ranjeshj
I see other people asking the same question. Is there any progress in the investigation of this issue?

@ranjeshj
Copy link
Contributor

@chingucoding Thanks for the PR. @StephenLPeters can you please review this PR ? Thanks!

@ranjeshj ranjeshj added this to the WinUI 2.5 milestone May 27, 2020
@ranjeshj ranjeshj added the needs-cherrypicktorelease PR tagged for cherry-pick to the current release branch (but not yet picked) label May 27, 2020
@ranjeshj ranjeshj removed the needs-cherrypicktorelease PR tagged for cherry-pick to the current release branch (but not yet picked) label Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TreeView bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants