Search code examples
silverlighttreeviewexpand

Programmatically show expand arrow on Silverlight TreeView


I have a Silverlight TreeView control that I'm dynamically populating when a specific node is clicked. For example, I load the first generation (level) of nodes, then when the user clicks on one of the nodes, I use the Selected event to populate that node's children, etc, etc. I'm sending back from my database a bool value with each node value that indicates whether or not the new nodes have children nodes.

I am wanting to set the expand arrow to show in front of new nodes that have a child, but the catch is that its children will not be populated yet. I thought maybe setting the HasChild to my bool value, but HasChild is read-only. Any suggestions would be very much appreciated.


Solution

  • Just a add blank treeviewitem when it's collapsed just to show the arrow.

    But when expanded by the user, clear that blank child, and do an async call to get the real children.

    Set the UserState to the parent treeviewitem or id when doing the GetChildrenAsync call.

    When they arrive, the UserState should be that parent treeviewitem or id, when you find that parent which you just set it's itemsource to the e.Result.