Skip to content

Custom TreeViewItem template not working correctly for type GridView #950

Open
@tmr4

Description

@tmr4

I created a tree view similar to your "Pictures and Music Library tree view" example except I replaced the text block in the data template with a grid view with two text blocks. This caused two problems with nested nodes: (1) when a node is expanded the first column of grid view items in the child nodes aren't rendered until you mouse over them, and (2) the child nodes are rendered out of order after expanding a second time (i.e., expanding a parent node, collapsing it and expanding it again). Internally the child nodes are still in the correct order because if you change to a simple text block data template while debugging the child nodes will be rendered instantly in the correct order.

Here is my data template using a grid view in which child nodes are rendered out of order on expanding the parent node a second time:
<DataTemplate x:Key="TreeViewItemDataTemplate1">
<GridView>
<TextBlock Text="{Binding Content.Column1Item}"/>
<TextBlock Text="{Binding Content.Column2Item}"/>
</GridView>
</DataTemplate>

This doesn't happen when using this simple data template (Content displays the ToString of the class):
<DataTemplate x:Key="TreeViewItemDataTemplate">
<Grid>
<TextBlock Text="{Binding Content}"/>
</Grid>
</DataTemplate>
If fact switching the data template live in xaml during a debug session will switch the order of the child nodes to the correct order.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

Pri2area-controlsdoc-bugfeedback is about something that is out of date, unclear, confusing, or broken in the articleeng-triagedwinui/tech

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions