私はXamarin Formsアプリケーションをしばらく開発していましたが、今はWindows Phoneプロジェクトを追加したいと思っています。私はMvvmCross GitHubプロジェクトのガイドでそれを設定しようとしましたが、古くなったようです。MvvmCrossでXamarin FormsソリューションでWindows Phone 8.1プロジェクトを設定する
まず、Windows Phone 8.1の空のアプリケーションプロジェクトをソリューションに追加し、ガイドを進めました。私は必要なNuGetパッケージを追加しましたが、問題はありませんでしたが、App.xaml.csファイルとMainPage.xaml.csファイルを変更すると、サンプルで使用されたクラスを使用できませんでしたチュートリアル。プロジェクトのリファレンスとサンプルMvvmCrossプロジェクトのリファレンスを比較すると、いくつかの違いがあります。
私には不審な事は、このMvvmCross.Forms.Presenter.Windows81参照です。 Xamarin FormsのMvvmCrossリポジトリを見た後、MvvmCross.Forms.Presenter.WindowsPhone名前空間がビュープレゼンターと一緒にあることが分かりました。だから私は考えていた、おそらくここに問題がある。
Xamarin.Formsガイドと私のUWPプロジェクトでコードを試してみると、アプリケーションが何らかの形で凝視されていて、実行すべきメソッドが実行されている場所に来ています(私がMvvmCrossガイド、私の最初のビューモデルが構築されていない)が、アプリケーションは非常にこのスタックトレースでbegginingでクラッシュしている:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// TODO: change this value to a cache size that is appropriate for your application
rootFrame.CacheSize = 1;
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// Removes the turnstile navigation for startup.
if (rootFrame.ContentTransitions != null)
{
this.transitions = new TransitionCollection();
foreach (var c in rootFrame.ContentTransitions)
{
this.transitions.Add(c);
}
}
rootFrame.ContentTransitions = null;
rootFrame.Navigated += this.RootFrame_FirstNavigated;
}
Setup setup = new Setup(rootFrame);
setup.Initialize();
IMvxAppStart start = Mvx.Resolve<IMvxAppStart>();
start.Start();
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
// Ensure the current window is active
Window.Current.Activate();
}
メインページ:ここ
System.TypeLoadException was unhandled by user code
HResult=-2146233054
Message=Could not find Windows Runtime type 'Windows.Foundation'.
Source=mscorlib
TypeName=Windows.Foundation
StackTrace:
at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at MvvmCross.WindowsCommon.Views.MvxWrappedFrame.Navigate(Type viewType, Object parameter)
at MvvmCross.Forms.Presenter.Windows81.MvxFormsWindows81PagePresenter.CustomPlatformInitialization(NavigationPage mainPage)
at MvvmCross.Forms.Presenter.Core.MvxFormsPagePresenter.TryShowPage(MvxViewModelRequest request)
at MvvmCross.Forms.Presenter.Core.MvxFormsPagePresenter.Show(MvxViewModelRequest request)
at MvvmCross.WindowsCommon.Views.MvxWindowsViewDispatcher.<>c__DisplayClass2_0.<ShowViewModel>b__0()
at MvvmCross.WindowsCommon.Views.MvxWindowsMainThreadDispatcher.RequestMainThreadAction(Action action)
at MvvmCross.WindowsCommon.Views.MvxWindowsViewDispatcher.ShowViewModel(MvxViewModelRequest request)
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModelImpl(Type viewModelType, IMvxBundle parameterBundle, IMvxBundle presentationBundle, MvxRequestedBy requestedBy)
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel[TViewModel](IMvxBundle parameterBundle, IMvxBundle presentationBundle, MvxRequestedBy requestedBy)
at MvvmCross.Core.ViewModels.MvxAppStart`1.Start(Object hint)
at PatrolHelper.WinPhone81.App.OnLaunched(LaunchActivatedEventArgs e)
は私App.xaml.csファイルの実装です.xaml:
<forms:WindowsPhonePage
x:Class="PatrolHelper.WinPhone81.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PatrolHelper.WinPhone81"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
</Grid>
とMainPage.xaml.cs
public sealed partial class MainPage : WindowsPhonePage
{
public MainPage()
{
this.InitializeComponent();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsWindows81PagePresenter;
LoadApplication(presenter.MvxFormsApp);
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
}
}
Windows Phone SilverlightまたはWindows PhoneのWinRTベースのアプリですか? –
これはWinRTアプリ – dobowicz
です。最初のページを開くときにアプリがクラッシュしています。静的リソースが定義されていますか?サンプルプロジェクトをどこかにアップロードすることは可能ですか? –