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.
: MvxFormsWindowsPage
parent class fromMainPage
. – Nico Zhu - MSFT