FormsPresenters: Setting Up MvvmCross with Xamarin.Forms

FormsPresenters: Setting Up MvvmCross with Xamarin.Forms

During the last months, we have made some improvements to the FormsPresenters plug-in taken from real-world projects we are working on with our customers, at Plain Concepts. Since we did not have some NuGet packages to make an easy install of the scaffolding needed, we dedicated some effort to add a small documentation to the GitHub repository it-self, so everyone can easily set-up MvvmCross on their Xamarin.Forms projects.

The first step is to clone the entire repo. locally, and build the MvvmCross submodule. Apart from here, the rest of the steps are done within the FormsPresenters directory. You will find four different projects inside: Core one, which handles the common logic among every supported platform (Android, iOS and Windows Phone); and one project per supported platform, which basically contains the final Presenters.

Prior to the steps to configure the FormsPresenters plug-in, it is needed to add MvvmCross NuGet packages to the solution. This will create the default scaffolding with Views per platform and a dummy ViewModel (NOTE: these Views are platform-specific, not yet Xamarin.Forms ones.)

Core with Core

The FormsPresenters Core PCL must be built first, and then referenced to the Core project of your app.


Just after building the FormsPresenters Droid project, reference it to the final Android project and please follow the instructions located at TODO.txt file.


Following the same criteria as Android, under the Touch project there is another TODO.txt guidelines file.

Windows Phone

Yes, you are right: build the WindowsPhone project and follow TODO.txt.

Now that the plug-in is fully configured, you can remove the Views folders created on the final platform projects, since those will be consumed now from your Core one, where the Xamarin.Forms pages will live. You can now add a Xamarin.Forms Page matching the ViewModel put by MvvmCross packages. Here there is a working sample which goes a little bit further, but shares the same process explained above.

If everything went fine, you can now run every platform app and see the default View/ViewModel created when MvvmCross is initially installed from NuGet.

Marcos Cobeña Morián

Post a Comment