Jeremy Sullivan
Jeremy Sullivan

Reputation: 1005

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.

Upvotes: 0

Views: 2167

Answers (2)

Paully
Paully

Reputation: 570

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.

Upvotes: 1

Tristan Warner-Smith
Tristan Warner-Smith

Reputation: 9771

If you're familiar with dependency properties, you could create a dependency property that would be settable by you in code and gettable in the xaml so it could be bound to.

This would allow you to use a ValueConverter to render the visibility of the arrow.

Upvotes: 0

Related Questions