Skip to content
New issue

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

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

Already on GitHub? # to your account

TreeViewItem Template IsExpanded ignored when reused #1790

Closed
michael-hawker opened this issue Dec 24, 2019 · 7 comments · Fixed by #1917 or #1924
Closed

TreeViewItem Template IsExpanded ignored when reused #1790

michael-hawker opened this issue Dec 24, 2019 · 7 comments · Fixed by #1917 or #1924
Assignees
Labels
area-TreeView team-Controls Issue for the Controls team

Comments

@michael-hawker
Copy link
Collaborator

Describe the bug

        <muxc:TreeView x:Name="SyntaxTree"
                       ItemsSource="{x:Bind RootNodes, Mode=OneWay}">
            <muxc:TreeView.ItemTemplate>
                <DataTemplate x:DataType="local:XmlSyntaxData">
                    <muxc:TreeViewItem ItemsSource="{x:Bind Children}"
                                       IsExpanded="True">
                       <TextBlock Text="{Binding}"/>
                    </muxc:TreeViewItem>
                </DataTemplate>
            </muxc:TreeView.ItemTemplate>
        </muxc:TreeView>

I have a dependency property named RootNodes (a List of a hierarchical data type) bound to the TreeView. When I set this property the first time, the tree view populates items from the data structure and all the nodes are expanded as would be expected.

When I set this property again a 2nd time and change the list, the tree view items are regenerated; however, they are now not in an expanded state. They should be in an expanded state.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Use XAML structure above to configure a set of TreeViewItems
  2. Replace the itemssource reference

Expected behavior
All TreeViewItems should be expanded as specified in the template.

Screenshots
First time:
image

Second time:
image

(Sometimes inconsistent results, e.g. first node will be expanded, but only first node, all other nodes still collapsed, unlike initial behavior.)

Version Info
NuGet package version: Microsoft.UI.XAML 2.3.191211002

Windows 10 version Saw the problem?
Insider Build (19041.1) Yes
May 2019 Update (18362)
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
@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Dec 24, 2019
@michael-hawker
Copy link
Collaborator Author

This is from a sample I've been working on, I need to publish it, so I can share a full example eventually. This piece is just getting in the way of the core experience for the sample, so I need to figure out a workaround.

I actually just noticed even in the initial generation, some of the deeper nodes don't expand, so there may be something else going on even initially as well?

@ranjeshj ranjeshj added team-Controls Issue for the Controls team area-TreeView and removed needs-triage Issue needs to be triaged by the area owners labels Jan 2, 2020
@ranjeshj
Copy link
Contributor

ranjeshj commented Jan 2, 2020

@kaiguo, can you please take a look ?
I'm curious if this is a timing issue between when the TreeViewItem gets children bound to it vs when the IsExpanded property is set. TreeViewItem has an ItemsSource dependency property - so perhaps as a workaround, when that propertychanges, you could manually expand the children.

@michael-hawker
Copy link
Collaborator Author

@ranjeshj @kaiguo thinking about this more if it's a timing with the items being loaded from the itemssource, could it be that the isexpanded needs to be updated in the itemssource property changed like the opacity line here too?

@ranjeshj
Copy link
Contributor

@michael-hawker. Good catch. That is quite possibly what is causing it. Can you try updating isExpanded when ItemsSource changes and see if that fixes the issue ?

@michael-hawker
Copy link
Collaborator Author

Thanks @kaiguo!

@ranjeshj when will I know that the fix has made it in a build? I can test it out from the NuGet easily when it's in a package.

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Jan 31, 2020
@ranjeshj
Copy link
Contributor

ranjeshj commented Feb 1, 2020

@michael-hawker for testing you can use the nuget package from the PR build artifacts.

@msft-github-bot
Copy link
Collaborator

🎉This issue was addressed in #1924, which has now been successfully released as Microsoft.UI.Xaml v2.4.0-prerelease.200322001.:tada:

Handy links:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-TreeView team-Controls Issue for the Controls team
Projects
None yet
4 participants