Non Shared View

Mar 28, 2011 at 12:36 PM

Thanks for integrating NonShared in Jounce, I maybe missed something but I think your way to do it miss the possibility to recall a created non shared VM or View.

Imagine a Tab Control with a List of Contact (only the model) and you can open each contact in a new Tab.

You open Contact A then Contact B

The Tab Control will be like that :

List | Contact A | Contact B

 

You go on list and open Contact A again, how with can we display the already opened Contact A and not a new one?

Coordinator
Mar 28, 2011 at 12:42 PM

I'm not sure I quite understand the issue. If I were to implement that, I would have the tabs each be a generated view with the view model. The list can hold the generated view models for the contacts, and when you click, you can simply determine if a view for that contact has been created or not. If you open a new tab, great, spin up the view and bind the view model. If you go back to the list box and click the same contact, you'll jump to that tab. If you close it, then click it again, a new view spins up but the same view model is used because the view model is held in the list, no?

I'm not sure if that answers your question, but if there is something you believe Jounce should be doing, what is that - should Jounce be tracking all of your view instances for you? If so, how do you know "which view is which" or "which view model is which"? I purposefully left that out of Jounce to not dictate how you manage the lifetime of non-shared views.

Mar 28, 2011 at 2:53 PM

I know your solution but not working if you are on your Contact B and he is a parent of Contact A by example, if you want to give the possibility to open the contact from B then how will you do it.

I think the best way is to keep the track of all non shared and use a Id property or a GetId() Method on VM and a way to get it from View.

Coordinator
Mar 28, 2011 at 3:00 PM

I guess I'm still not tracking the problem. What do you mean by "Contact B" being a parent of "Contact A"? Parent how - in the visuall tree? Nested views? Something else? I definitely want to understand the problem so I can either help provide a solution or update Jounce to make it easier but I've still not run into this issue so I'm probably not understanding it correctly.

I'd have a "mainviewmodel" that tracks a list<contactviewmodel>. I'd likely override the Equals/GetHashCode to return an identifier on the contact so the view model is unique by the contact it envelopes. Any trigger to open the contact tab would fire an event. The event keeps track of open contact ids. If it already opened one, it simply activates that tab. If not, it adds a new tab and activates a new view and binds to the view model. That's the scenario as I see it but sounds like something different might exist in your example.

Mar 28, 2011 at 3:52 PM

Sorry, I m not clear.

I mean Contact B is the wife of Contact A by example and on the Contact Form you have a Hyperlink button for Open the Wife contact form in the TabControl.

I see your way to do it.

I did a similar way but in a Generic Way with Another Event and Router and keeping the NonSharedView/NonSharedViewModel in a list of View and a list of ViewModel(All VM implement an interface with GetId() ).