Search code examples
xamarin.formsmvvmcross

How to setup my UWP project with Xamarin.Forms and MvvmCross


I have a Xamarin.Forms solution using MvvmCross. I have the Android project working correctly with it. I want to add a UWP project to use with my Forms project, but I can not find any documentation on how I can create a UWP project with my Forms and MvvmCross setup.


Solution

  • The MvvmCross Forms UWP Playground Project helped a lot, great for any fundamentals. Here is the solution for anyone else that wants it:

    Change App.xaml to

    <local:MyApp
        x:Class="MyApp.UWP.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyApp.Forms.UWP"
        RequestedTheme="Light">
    
    </local:MyApp>
    

    And in App.xaml.cs:

    sealed partial class App
    {
        public App()
        {
            InitializeComponent();
        }
    }
    
    public abstract class MyApp : MvxWindowsApplication<MvxFormsWindowsSetup<Core.App, Forms.App>, Core.App, Forms.App, MainPage>
    {
    }
    

    And MainPage.xaml:

    <mvxf:MvxFormsWindowsPage
        xmlns:mvxf="using:MvvmCross.Forms.Platforms.Uap.Views"
        x:Class="MyApp.Forms.UWP.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyApp.Forms.UWP"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    
        </Grid>
    </mvxf:MvxFormsWindowsPage>
    

    MainPage.xaml.cs

    public sealed partial class MainPage
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }