In our current project Privatbilanz we had the problem that we have to manage the state of the IsExpanded property in a treeview.
- Data Access Layer: Entity Framework
- WCF RIA Services
- Silverlight client
After each manipulation of our nodes of the treeview, we have to call the WCF service to give us back the fresh list of nodes. After this action the tree will have has initial look – all nodes are collapsed :-(
So what we did now was to extend our data model at the client side with a partial class to define for our entity a IsExpanded property.
Step 1 – Extend entity
Note: You have to use the same namepace as your model at the service side (WCF RIA Services)
Step 2 – Bind the property to UI
Because in our case the control is a TreeviewItem we have to do this in our style definition. Unfortunately Silverlight does not support this kind of binding at the normal way – WPF is at this point much better.
So what we have to do additional is to define a helper class SetterValueBindingHelper. We found this really useful class at Delay’ Blog: