View life span

Jul 28, 2010 at 4:46 PM

Hello there,

 

I have master/details view.

Details area is bound to active item, selected in master view. Also, details view is a named ContentControl, which dynamically instantiated corresponding view. So far so good.

However, details view  is very complex visually. So I noticed, that instead of rebind the new active item to the existing details view, Caliburn always creates a fresh view.

 

The question is, how do I force Caliburn to not recreate view, if same view class is already instantiated in the ContentControl?

 

P.S. If I apply MEF [Export] attribute to the view, view is not recreated, but it makes impossible to use the same view class in two places simultaneously.

Also, rebinding is not happened with the new view model. 

 

Coordinator
Jul 28, 2010 at 4:53 PM

Inherit your detail VM from Screen or implement IViewAware. That will let you tell the framework how to find the existing view.

Jul 28, 2010 at 5:35 PM

The problem is that no data binding happens if view is already bound to another details view model.

if ((bool)view.GetValue(ConventionsAppliedProperty)) return;

This line blocks the re-binding.

Coordinator
Jul 28, 2010 at 6:28 PM

Ok. I will move that check farther down in the logic so that it always sets Action.Target and uses IViewAware, but only exits convention creation in that case. Just give me a day or two :) Lots going on right now...