ZoolWay
ZoolWay

Reputation: 5505

Reusing view instances with Caliburn.Micro

I have got a view containing sub-views with ContentControls like this

<ContentControl x:Name="DetailView" />

This works fine. When I change the contents for the ContentControl to another ViewModel it will load the other ViewModel and view. But when I change back to the ViewModel from before it will not reuse the view instance but create a new one. Note: I do not assign a new instance of the first ViewModel but excatly the same one.

How can I say Caliburn.Micro to reuse the instance of the view from before rather than creating a new view instance?

Upvotes: 2

Views: 729

Answers (1)

StepUp
StepUp

Reputation: 38134

What IoC container do you use to create instances of View and ViewModels?

Just create a single instance of <ContentControl/>. Let me show how to create a singleton in IoC container Unity:

container.RegisterType<IViewContentControl, ConentControl>(
                        new ContainerControlledLifetimeManager()); 

where ContainerControlledLifetimeManager() means that there is just one instance in the whole lifecycle of your application.

Upvotes: 1

Related Questions