re-use ViewModels for sub controls?

Topics: Issues / bugs
Aug 21, 2012 at 5:35 AM
Edited Aug 21, 2012 at 5:51 AM


I have a window containing a nested structure of usercontrols.
They all share the same Model instance.
So I thought it would be ok to share the same ViewModel instance, too.
So the sub controls are declared as <SomeControl DataContext="{Binding}" />

This seems to work until switching to another model (change record).
Then there is a loop calling ViewModelClosing/ViewModelClose recursive.
The program breaks with a stack overflow.

I think this is because of the canceling of the nested VMs.
Because these are in fact the same instance, the VM calls itself to cancel repeating.
I assume there will be some other caveats I heaven't been faced to so far. 

Sure, I have read your docs about the "Nested user controls problem", more then once.
And I think I understand how it works.
But my situation is somehow different to the House/Room/Table/Chair example shown there.

I have a model describing details about a contact.
The model is made by rich objects using CSLA.NET.
Validation, Saving, Canceling, CanSave, CanCancel and so on are available on the model for the whole object graph.
I think this is rivaling with the accordingly methods provided by catel.

To separate gui design parts, I design several usercontrols displaying parts of data from the same level of the object graph.
So there is really the same model instance with data displayed in parts on different views.
And not only a usercontrol per object graph level. 

How should I address these issues?

thanks, alex.

Aug 21, 2012 at 11:10 AM

Interesting. If you provide a reproducable case, then I will fix this issue for 3.3. We will be releasing a beta this week.

Aug 22, 2012 at 6:46 AM

I have created an issue:
Attached you can find the sample. Build against the Catel 3.2.1208211816-beta Version. 


Aug 24, 2012 at 6:23 PM

Issue solved, currently building a new nightly build with the fix.

Aug 28, 2012 at 7:09 AM

Just tested the fix, works great!
Thank you!