Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Singleton instance of ViewModels?

$
0
0

I have many activities (forms) in my app. All these views are connected to their view-models using following code-

ViewFactory.Register<LocationView,LocationViewModel> ();

If I have a main menu from where user can navigate to Screen A or B. Navigating to Screen A creates a new instance of Screen A view model based on the code above. However when I navigate back to main menu and navigate to screen A again, will a new instance gets created again? This will cause so many instances of Screen A in the app. I am noticing crashes randomly when navigating in my app.

Can I register singleton with ViewFactory to avoid this problem? Or does ViewFactory always uses same instance whenenver I navigate to a view model?

Thanks

Apurva


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>