2016-07-01 9 views
1

Ich habe ein Xamarin.Forms Projekt mit einem WinPhone 8.1-Projekt, das Caliburn.Micro verwendet.WinPhone 8.1 Projekt mit Xamarin.Forms und Caliburn.Micro Failes zu erstellen

Das ist mein App.xaml:

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; 
    } 
} 

}

Dies sind die NuGet Pakete:

<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" /> 

Das ist mein App.xaml.cs ist

enter image description here

Es kompiliert, aber wenn ich versuche, es zu laufen, erhalte ich die folgende Ausnahme bei DisplayRootView.

konnte nicht Windows-Runtime-Typ 'Windows.Foundation' gefunden ":" 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) 

Können Sie mir sagen, was ich tun soll?

UPDATE:

Die Wurzel des Problems in diesem Teil des Codes liegt:

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; 
    } 

Es scheint, dass mein eingehender Mainview nicht in einen entsprechenden XAML-Typen umgewandelt werden kann, wie GetXamlTypeByType Renditen Null.

enter image description here

enter image description here

ich, dass die Welt Xamarin.Forms Ansicht ist nicht kompatibel mit dem WinPhone scheint ... na ja, sollte Xamarin.Forms über abstrakte Ansichten sein, wenn ich mich richtig erinnere.

Was soll ich jetzt tun?

+0

Ich habe genau das gleiche Problem beim Versuch, es mit WinPhone 8.1 funktioniert. Caliburn Micro 3.0.1 und neueste Xamarin.Forms. – GrzegorzM

+0

@Mrozu Überprüfen Sie die Antwort, die ich zur Verfügung gestellt habe. – Nestor

Antwort

0

Nachdem ich sorgfältig in der Xamarin Forms tutorial gelesen habe, wie eine Windows Phone 8.1-Anwendung hinzugefügt und entsprechend geändert wurde, funktionierte alles wie erwartet.

In meinem Fall hat die MainPage.xaml.cs ihren ursprünglichen Code, wie ich es nicht gemäß dem Tutorial geändert habe.

public sealed partial class MainPage // REMOVE ": PhonePage" 

Als Caliburn.Micro die Xamarin Infrastruktur verwendet werden diese Schritte erforderlich.

Verwandte Themen