Caliburn.Microを使用する WinPhone 8.1 プロジェクトを含むXamarin.Formsプロジェクトがあります。
これは私の App.xaml です:
<caliburn:CaliburnApplication x:Class="MyProject.WinPhone.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:caliburn="using:Caliburn.Micro"
xmlns:local="using:MyProject.WinPhone" />
これは私の App.xaml.cs です:
public sealed partial class App : Caliburn.Micro.CaliburnApplication
{
private WinRTContainer container;
private TransitionCollection transitions;
public App()
{
InitializeComponent();
}
protected override void Configure()
{
container = new WinRTContainer();
container.RegisterWinRTServices();
//TODO: Register your view models at the container
container.PerRequest<MainViewModel>();
}
protected override object GetInstance(Type service, string key)
{
var instance = container.GetInstance(service, key);
if (instance != null)
return instance;
throw new Exception("Could not locate any instances.");
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
container.BuildUp(instance);
}
protected override void PrepareViewFirst(Frame rootFrame)
{
container.RegisterNavigationService(rootFrame);
}
protected override IEnumerable<Assembly> SelectAssemblies()
{
return new[] { typeof(MainViewModel).GetTypeInfo().Assembly, typeof(Windows.Foundation.AsyncActionCompletedHandler).GetTypeInfo().Assembly };
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
return;
try
{
DisplayRootView<MainView>();
//DisplayRootView<MainPage>();
//DisplayRootViewFor<MainViewModel>();
}
catch (Exception ex)
{
var x = 8;
throw;
}
}
}
これらは NuGet パッケージです。
コンパイルはできますが、実行しようとすると、次の例外が発生しDisplayRootView
ます:
Windows ランタイム タイプ 'Windows.Foundation' が見つかりませんでした。":"Windows.Foundation
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 Caliburn.Micro.CaliburnApplication.DisplayRootView(Type viewType, Object paramter)
at Caliburn.Micro.CaliburnApplication.DisplayRootView[T](Object parameter)
at MyProject.WinPhone.App.OnLaunched(LaunchActivatedEventArgs args)
これについて私が何をすべきか教えてもらえますか?
アップデート:
問題の根本は、コードの次の部分にあります。
private global::MyProject.WinPhone.MyProject_WinPhone_XamlTypeInfo.XamlTypeInfoProvider _provider;
public global::Windows.UI.Xaml.Markup.IXamlType GetXamlType(global::System.Type type)
{
if(_provider == null)
{
_provider = new global::MyProject.WinPhone.MyProject_WinPhone_XamlTypeInfo.XamlTypeInfoProvider();
}
return _provider.GetXamlTypeByType(type);
}
public global::Windows.UI.Xaml.Markup.IXamlType GetXamlType(string fullName)
{
if(_provider == null)
{
_provider = new global::MyProject.WinPhone.MyProject_WinPhone_XamlTypeInfo.XamlTypeInfoProvider();
}
return _provider.GetXamlTypeByName(fullName);
}
public global::Windows.UI.Xaml.Markup.XmlnsDefinition[] GetXmlnsDefinitions()
{
return new global::Windows.UI.Xaml.Markup.XmlnsDefinition[0];
}
}
}
namespace MyProject.WinPhone.MyProject_WinPhone_XamlTypeInfo
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks", "4.0.0.0")]
internal partial class XamlTypeInfoProvider
{
public global::Windows.UI.Xaml.Markup.IXamlType GetXamlTypeByType(global::System.Type type)
{
global::Windows.UI.Xaml.Markup.IXamlType xamlType;
if (_xamlTypeCacheByType.TryGetValue(type, out xamlType))
{
return xamlType;
}
int typeIndex = LookupTypeIndexByType(type);
if(typeIndex != -1)
{
xamlType = CreateXamlType(typeIndex);
}
var userXamlType = xamlType as global::MyProject.WinPhone.MyProject_WinPhone_XamlTypeInfo.XamlUserType;
if(xamlType == null || (userXamlType != null && userXamlType.IsReturnTypeStub && !userXamlType.IsLocalType))
{
global::Windows.UI.Xaml.Markup.IXamlType libXamlType = CheckOtherMetadataProvidersForType(type);
if (libXamlType != null)
{
if(libXamlType.IsConstructible || xamlType == null)
{
xamlType = libXamlType;
}
}
}
if (xamlType != null)
{
_xamlTypeCacheByName.Add(xamlType.FullName, xamlType);
_xamlTypeCacheByType.Add(xamlType.UnderlyingType, xamlType);
}
return xamlType;
}
GetXamlTypeByType
nullを返すため、受信した MainView を適切な XAML タイプに変換できないようです。
Xamarin.Forms ビューは WinPhone の世界と互換性がないようです...まあ、正しく思い出せば、Xamarin.Forms は抽象ビューに関するものでなければなりません。
私は今どうすればいい?