我正在尝试使用Mvvmcross的Xamarin.Forms主细节导航。
App.cs
public partial class App : MvxFormsApp
{
public App()
: base()
{
// The root page of your application
DependencyService.Register<AppContext>();
InitializeComponent();
// MainPage = new MasterDetail(); doing this would raise an InvalidCastException
}
protected override void OnParentSet()
{
}
protected override void OnStart()
{
base.OnStart();
// Handle when your app starts
// Initiate Navigation and navigate to the splashscreen
}
...
的App.xaml:
<core:MvxFormsApp
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Stago.Mhp.Instr.Pocm.Core.Controls;assembly=Stago.Mhp.Instr.Pocm.Core"
xmlns:converters="clr-namespace:Stago.Mhp.Instr.Pocm.Core.Converters;assembly=Stago.Mhp.Instr.Pocm.Core"
xmlns:forms9Patch="clr-namespace:Forms9Patch;assembly=Forms9Patch"
xmlns:core="clr-namespace:MvvmCross.Forms.Presenter.Core;assembly=MvvmCross.Forms.Presenter.Core"
x:Class="Stago.Mhp.Instr.Pocm.Core.App">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="BlackC90">#414142</Color>
<Color x:Key="BlackC50">#939598</Color>
<Color x:Key="BlackC05">#F1F1F2</Color>
<Color x:Key="Black.20">#33000000</Color>
<Color x:Key="Blue">#008DA8</Color>
<Color x:Key="Red">#EE3524</Color>
<Color x:Key="Orange">#F6A01A</Color>
<Color x:Key="White">#F8F8F8</Color>
...
MvxFormsApplicationActivity.cs(Droid方面)
[Activity(Label = "MvxFormsApplicationActivity", ScreenOrientation = ScreenOrientation.Portrait)]
public class MvxFormsApplicationActivity : FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Forms.Init(this, bundle);
var mvxFormsApp = new App();
mvxFormsApp.MainPage = new MasterDetail();
LoadApplication(mvxFormsApp);
var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsDroidPagePresenter;
presenter.MvxFormsApp = mvxFormsApp;
Mvx.Resolve<IMvxAppStart>().Start();
}
}
不幸的是,没有考虑ResourceDictionary,我的应用程序没有被设计。
如果我删除mvvmcross集成并直接从Application(当然是App.cs和App.Xaml)继承,它就可以了。
修改对于那些从头开始关注此问题的人:通过将主页面分配放在MvxFormsApplicationActivity
中来解决异常。