views:

22

answers:

2

I am trying to do some databinding magic. I have a Shipments view that lists shipments, and provides filtering and ordering ability on the list. The filter string box, Delivery Status filters (checkboxes) and Ordering Radiobuttons are databound to properties in the ViewModel. I want to add the ability to save state and I have elected to do this by saving control states in an xml document. Previously I have done this before with little problem, using databinding to just read/write the values back and forth.

However, now I have a quandry. My filter controls are currently databound to items in the ViewModel. i can write code that changes their databinding from the xml to the ViewModel on load and vice versa, but that would be messy.

Is there a mechanism in place that I can use to achieve the ability to bind to two equal sources and have them updated at the same time?

+1  A: 

None that I'm aware of.

My opinion: I really wouldn't do this anyway - if your datacontext is the viewmodel, and the viewmodel has properties for the filter, you almost certainly should be persisting and retrieving the relevant viewmodel state to keep the state of the filters. Trying to save controlstate, then retrieve it, set it, and set the viewmodel based on the new controlstate sounds like a lot more work and much more prone to bugs.

Philip Rieck
+2  A: 

This sounds like a concern for the view model.

Why not load the saved values into the view model, and have the view model decide what data to expose?

Then the view doesn't have to be concerned with managing data.

Jay
I think I will work it as you describe. For the Filter related items, I will store/retrieve XML in the VM code to save state between sessions, for other non-ViewModel related items, I can just databind to an XML datasource, all saving on View close.
OffApps Cory