0
votes

VS2017 version 15.9.3, Xamarin Forms 3.4, Mvvmcross 6.2.2

In VS2017, it's happy to produce Android, Ios and UWP projects with a common Xamarin forms project.

I'm interested in using MVVMCross to support MVVM and reduce boilerplate code.

The MVVMCross website gives a tutorial on how to make a UWP TipCalc but not a Xamarin.Forms.UWP TipCalc that shares UI code with Android and Ios.

I thought that if I took the UWP Tipcalc project, removed the views and referenced the Forms.UI and Forms.Core project, it would link up properly, but obviously not.

App.xaml

<local:TipCalcApp x:Class="MX_TipCalc.UWP.UWP.App"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="using:MX_TipCalc.Forms.UWP.UWP"
          RequestedTheme="Light">
    <Application.Resources>
        <x:String x:Key="WelcomeText">Hello World!</x:String>
    </Application.Resources>
</local:TipCalcApp>

App.xaml.cs

using MvvmCross.Platforms.Uap.Core;
using MvvmCross.Platforms.Uap.Views;

namespace MX_TipCalc.Forms.UWP.UWP
{
    public sealed partial class App
    {
        public App()
        {
            InitializeComponent();
        }
    }

    public abstract class TipCalcApp : MvxApplication<MvxWindowsSetup<Core.App>, Core.App>
    {
    }
}

What does it take to get an MVVMCross Xamarin.Forms.UWP project to hook up with the TipCalc.Forms.UI and the TipCalc.Forms.Core to get it working?

Thanks

So after the answer by Nico Zhu - MSFT My App.xaml is

<local:TipCalcApp x:Class="MX_TipCalc.Forms.UWP.UWP.App"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="using:MX_TipCalc.Forms.UWP.UWP"
                    RequestedTheme="Light">
    <Application.Resources>
        <x:String x:Key="WelcomeText">Hello World!</x:String>
    </Application.Resources>
</local:TipCalcApp>

My App.xaml.cs is

using MvvmCross.Forms.Platforms.Uap.Core;
using MvvmCross.Forms.Platforms.Uap.Views;
using MX_TipCalc.Forms.UI;

namespace MX_TipCalc.Forms.UWP.UWP
{
    public sealed partial class App
    {
        public App()
        {
        InitializeComponent();
       }
    }

    //public abstract class TipCalcApp : 
MvxApplication<MvxWindowsSetup<Core.App>, Core.App>
    //{
    //}

    public abstract class TipCalcApp : MvxWindowsApplication<MvxFormsWindowsSetup<Core.App, FormsApp>, Core.App, FormsApp, MainPage>
    {
    }
}

My MainPage.xaml is

<mvxf:MvxFormsWindowsPage
   xmlns:mvxf="using:MvvmCross.Forms.Platforms.Uap.Views"
   x:Class="MX_TipCalc.Forms.UWP.UWP.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="using:MX_TipCalc.Forms.UWP.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>

My MainPage.xaml.cs is

   using MvvmCross.Forms.Platforms.Uap.Views;

   namespace MX_TipCalc.Forms.UWP.UWP
   {
       public partial class MainPage : MvxFormsWindowsPage
       {
       public MainPage()
           {
               InitializeComponent();
           }
       }
   }

The good news - it now builds without a problem.

The bad news - it comes up with a System.AccessViolation Exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

I put a break point in MX_TipCalc.Forms.UWP.UWP.App.xaml.cs

Public App() InitializeComponent

after that it goes to

    static void Main(string[] args)
    {
        global::Windows.UI.Xaml.Application.Start((p) => new App());
    }

then

    /// <summary>
    /// GetXamlType(String)
    /// </summary>
    public global::Windows.UI.Xaml.Markup.IXamlType GetXamlType(string fullName)
    {
        return _AppProvider.GetXamlType(fullName);
    }

After hitting the last curly brace while stepping, it crashes. That's the limit of my knowledge :-(

Next Step

My latest MainPage.xaml.cs is now

namespace MX_TipCalc.Forms.UWP.UWP
{
    public partial class MainPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
}

At first, I got messages of missing file "Interop.Manual.cs". I cleaned and rebuilt the solution/projects several times. Eventually, that message did not reappear. I checked that TipCalc.UWP (non Forms version) worked and that TipCalc.Forms.Droid worked. Yep, they still work but when I try the TipCalc.Forms.UWP it still crashes at the same place as before.

1
Check the MvvmCross Playground.Forms.Uwp to see how to configure uwp platform with formsFabriBertani
Thanks. Downloaded Mvvmcross, Cleaned it, had 2 errors, Build it 237 errors. Seems to be missing lots of dll files. Do you know how I can get those restored/downloaded/created? like MvvmCross-develop\MvvmCross.Forms\bin\Debug\uap10.0.16299\MvvmCross.Forms.dll' MvvmCross-develop\MvvmCross.Plugins\JsonLocalization\bin\Debug\netstandard2.0\MvvmCross.Plugin.JsonLocalization.dll' How do I force VS2017 to get those from somewhere? ThanksAlan
I've looked at Playground.Forms.uwp project, in the references it refers to MvvmCross-develop\MvvmCross.Plugins\JsonLocalization\bin\Debug\netstandard2.0\MvvmCross.Plugin.JsonLocalization.dll and says Resolved : True ! But when I look at the location, the dll is not there!Alan
Please remove : MvxFormsWindowsPage parent class from MainPage.Nico Zhu - MSFT
Hi @Alan if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself.CoCaIceDew

1 Answers

1
votes

I have configured uwp platform with forms ui reference this link. You could refer the follow steps.

Add TipCalc.Forms.UI reference to TipCalc.UWP project.

enter image description here

Replace abstract class TipCalcApp with the following code

using MvvmCross.Forms.Platforms.Uap.Core;
using MvvmCross.Forms.Platforms.Uap.Views;
using TipCalc.Forms.UI;

namespace TipCalc.UWP
{
    public sealed partial class App
    {
        public App()
        {
            InitializeComponent();
        }
    }

    //public abstract class TipCalcApp : MvxApplication<MvxWindowsSetup<Core.App>, Core.App>
    //{
    //}
    public abstract class TipCalcApp : MvxWindowsApplication<MvxFormsWindowsSetup<Core.App, FormsApp>, Core.App, FormsApp, MainPage>
    {
    }

}

Modify the MainPage xaml as host page.

<mvxf:MvxFormsWindowsPage
    xmlns:mvxf="using:MvvmCross.Forms.Platforms.Uap.Views"
    x:Class="TipCalc.UWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TipCalc.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>

At last, remove TipView.xaml file from TipCalc.UWP project. Then it will work.