0

I'm currently styling HierarchicalDataTemplates for a TreeView. Each Item has a TextBlock which should display the items current hierarchical location in the TreeView:

> Item = 1  
>- Item = 1.1  
>-- Item = 1.1.1    
>- Item = 1.2  
> Item = 2

I looked up "AlternationCount" but i don't think this will provide the right solution.

How to retrieve or generate the current hierarchical location of an item inside a TreeView?

knorke T
  • 17
  • 7
  • Such id (or better - *address*) can be recursively generated from child collection. – Sinatr Jan 25 '19 at 09:51
  • Give sample of input. I usually point people to following link when using xml : https://stackoverflow.com/questions/28976601/recursion-parsing-xml-file-with-attributes-into-treeview-c-sharp – jdweng Jan 25 '19 at 10:03
  • The reason people are pointing you to recursion is because each treeviewitem is a headereditemscontrol https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.treeviewitem?view=netframework-4.7.2. The header is what you see as the Item and the itemscontrol holds it's children. Which can each have children. Each set of children is thus an itemscontrol and a totally discrete set of items. You therefore have to iterate through parent and it's children and each of their children... in order to set a property for this. – Andy Jan 25 '19 at 11:13

0 Answers0