Search code examples
c#xamarinxamarin.formsprism-6

How do I use Prism MVVM with a ContentView in Xamarin Forms?


What is the correct way to handle MVVM with Prism and content views?

I'm trying to port this Xamarin application to Prism (this contentview, and this code) and am unsure of the right way to do this.

Do I

  1. Create a ViewModel and then register them in my IContainerRegistry?
  2. Does the parent (outer) ViewModel contain the object that will be bound to?
  3. Can the parent view model communicate with the ContentView?

Solution

    1. You don't need a viewmodel defined for the ContentView.

    2. Yes the underlying viewmodel holds the data for the item in question hence the BindableProperty in the code behind for the ProfileStripView.

    3. It is a user control doesn't mean you can't have changes cross over between the "user control" which is what the ContentView is basically serving as in this case. In that case of data changes the properties would need backers for changes and the bindings setup accordingly to allow for changes.

    All contentview really does is give the ability to get cleaner appearance to an already cluttered screen in a reusable package which is setup for 1 type in this case Athlete. They are equivalent to Fragments in Android and in Windows UWP/WPF they are ContentControls