Reputation: 1581
I'm working with the July '09 CTP of the .Net RIA services, and binding an object of Group=>Department=>Category objects to a treeview, and then having a hierarchialdatatemplate render each of the three object types.
What my end goal is for this will be to enable drag-n-drop functionality so that I can quickly edit my list of groups=>departments=>categories, and change their respective relationships in a more intuitive manner than what was previously available.
My current issue is that when I do the drop command, and submit the changes that need to be submitted to the data context, my treeview is redrawing, and collapsing the leaves. Is there a method by which I can use to avoid the collapse?
Upvotes: 1
Views: 980
Reputation: 31
I'm posting this answer purely for those who stumble upon this thread looking for an answer. (was done in SL4)
you'll need 2 lists:
you also must make sure that your Load operation has its LoadBehaviour set to Merge. for example:
domainContext.Load(domainContext.GetEntityQuery(), LoadBehavior.MergeIntoCurrent, CallbackFunction, userState);
so all that remains now is to call your domainContext.Load after each update and in your CallbackFunction replace your sourceList with the new list of entities returned by the web service. Since your Display list's drill down entries relies on association and the hierarchical Data template it should still be expanded on the entry that was just edited.
Note if you rebuild the DisplayList from scratch the treeview would obviously redraw\collapse.
Hope this helps someone. Jan
Upvotes: 3
Reputation: 7248
I've not done a lot of Silverlight work, but from what I've seen it has a pretty limited object model, so some of the events/properties/methods to do this may not be there. But you could try saving/restoring the state yourself... something akin to the following pseudo-code:
private expandeds as collection();
tree.OnNodeExpand() {
expandeds.add(tree.CurrentNode.key);
}
tree.OnNodeCollapse() {
expandeds.remove(tree.CurrentNode.key);
}
tree.AfterBind() {
for each key in expandeds {
tree.FindNodeByKey(key).expanded = true;
}
}
Upvotes: 0