Creating the UWP project

Now let us create the UWP project based on Xamarin.Forms. Add a new Blank App (Windows Universal) project to the solution:

Select the proper version of Windows 10:

Install the Xamarin.Forms package in the NuGet Package Manager:

Or use the command below in the Package Manager Console:

Then install the MvvmCross.Forms package in the NuGet Package Manager:

Or you can input the command below in the Package Manager Console:

Then add the references to the MvvmCrossDemo.Core project and the MvvmCrossDemo.Forms.UI project by right-clicking the MvvmCrossDemo.Forms.Uwp project in the solution explorer:

Open the App.xaml.cs file and add a new class with name UWPApplication, as shown below:

Update the App class to inherit from UWPApplication class and remove all the other pre-generated methods except for the constructor. Only keep the InitializeComponent() method in the constructor. You can find the source code of this file here: https://github.com/MvvmCross/MvvmCross/blob/develop/ContentFiles/Forms/UWPContent/App.xaml.cs.pp. At last, the App.xaml.cs look like this:

Accordingly, we need update the App.xaml file to update the base class to make it to inherit from the UWPApplication class, as shown below:

You can find the code of the App.xaml here: https://github.com/MvvmCross/MvvmCross/blob/develop/ContentFiles/Forms/UWPContent/App.xaml.pp.

Open the MainPage.xaml file and add the reference by this code:

Change the class of the MainPage to MvxFormsWindowsPage. The result is:

You can find the source code of this file here: https://github.com/MvvmCross/MvvmCross/blob/develop/ContentFiles/Forms/UWPContent/MainPage.xaml.pp.

Open the MainPage.xaml.cs and remove the base class of it, like this:

Find the sample code here: https://github.com/MvvmCross/MvvmCross/blob/develop/ContentFiles/Forms/UWPContent/MainPage.xaml.pp.

Now the UWP project based on Xamarin.Forms is done. Launch it and you will see the result:

Last updated

Was this helpful?