2017-05-07 9 views
0

새 Xamarin.Forms 프로젝트를 만들었으며 뷰 모델을 초기화하는 데 문제가 있습니다. 아무 반응이 없습니다. Features의 샘플을 사용하고 있습니다. 샘플 코드를 다음과 같이 수정했습니다.Caliburn.Micro Xamarin.Forms ViewModel이 초기화되지 않습니다.

public FormsApp(SimpleContainer container) 
    { 
     //... 

     DisplayRootView<ConductorView>(); 
    } 

예상대로 작동하지만 프로젝트에서 작동하지 않습니다.

.NET Standard 1.5 (이 문제를 일으키는 지 확실하지 않음)를 사용하고 있습니다.

using System; 
using Caliburn.Micro; 
using Caliburn.Micro.Xamarin.Forms; 
using UniversalSqlManager.ViewModels; 
using Xamarin.Forms; 
using INavigationService = Caliburn.Micro.Xamarin.Forms.INavigationService; 
using UniversalSqlManager.Views; 
namespace UniversalSqlManager 
{ 
    public class App : FormsApplication 
    { 
     private readonly SimpleContainer container; 

     public App(SimpleContainer container) 
     { 
      this.container = container; 

      container 
       .PerRequest<ShellViewModel>(); 

      this.DisplayRootView<ShellView>(); 
     } 

     protected override void PrepareViewFirst(NavigationPage navigationPage) 
     { 
      container.Instance<INavigationService>(new NavigationPageAdapter(navigationPage)); 
     } 
    } 
} 

ShellView.xaml :

<?xml version="1.0" encoding="utf-8"?> 
    <TabbedPage 
     xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     xmlns:local="clr-namespace:UniversalSqlManager" 
     x:Class="UniversalSqlManager.Views.ShellView" 
     xmlns:cm="clr-namespace:Caliburn.Micro.Xamarin.Forms;assembly=Caliburn.Micro.Platform.Xamarin.Forms" 
     ItemsSource="{Binding Items}" 
     SelectedItem="{Binding ActiveItem, Mode=TwoWay}" 
     Title="Universal SQL Manager"> 
     <TabbedPage.ItemTemplate> 
      <DataTemplate> 
       <ContentPage Title="{Binding DisplayName}" cm:View.Model="{Binding}" /> 
      </DataTemplate> 
     </TabbedPage.ItemTemplate> 
    </TabbedPage> 

ShellView.xaml.cs :

using Xamarin.Forms; 

    namespace UniversalSqlManager.Views 
    { 
     public partial class ShellView 
     { 
      public ShellView() 
      { 
       InitializeComponent(); 
      } 
     } 
    } 

ShellViewModel.cs 어떤 경우에는 여기에 내 코드

App.cs입니다 :

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using Caliburn.Micro; 
    using Caliburn.Micro.Xamarin.Forms; 
    using UniversalSqlManager.ViewModels.Interfaces; 

    namespace UniversalSqlManager.ViewModels 
    { 
     public class ShellViewModel : Conductor<ITabItem>.Collection.OneActive 
     { 
      protected override void OnInitialize() 
      { 
       //both view models implement ITabItem (which has no methods) and inherit form Screen 
       Items.Add(new ServersViewModel()); 
       Items.Add(new SettingsViewModel()); 

       ActivateItem(Items[0]); 
      } 
     } 
    } 
나는 이것을 ShellView을 실행할 때 그래서

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Reflection; 
    using Caliburn.Micro; 
    using UniversalSqlManager.ViewModels.Interfaces; 

    namespace UniversalSqlManager.iOS 
    { 
     public class CaliburnAppDelegate : CaliburnApplicationDelegate 
     { 
      private SimpleContainer container; 

      public CaliburnAppDelegate() 
      { 
       Initialize(); 
      } 

      protected override void Configure() 
      { 
       container = new SimpleContainer(); 
       container.Instance(container); 
       container.Singleton<App>(); 
       container.Singleton<IEventAggregator, EventAggregator>(); 
      } 

      protected override void BuildUp(object instance) 
      { 
       container.BuildUp(instance); 
      } 

      protected override IEnumerable<object> GetAllInstances(Type service) 
      { 
       return container.GetAllInstances(service); 
      } 

      protected override object GetInstance(Type service, string key) 
      { 
       return container.GetInstance(service, key); 
      } 
     } 
    } 

:

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using Caliburn.Micro; 

    using Foundation; 
    using UIKit; 

    namespace UniversalSqlManager.iOS 
    { 
     [Register(nameof(AppDelegate))] 
     public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
     { 
      private readonly CaliburnAppDelegate appDelegate = new CaliburnAppDelegate(); 

      public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
      { 
       global::Xamarin.Forms.Forms.Init(); 

       LoadApplication(IoC.Get<App>()); 

       return base.FinishedLaunching(app, options); 
      } 
     } 
    } 

CaliburnAppdelegate.cs : 그게 내가

AppDelegate.cs에서 테스트하고있어 첫 번째 플랫폼의로

나는 아이폰 OS 보여주지 UI가 나타나지만 ShellViewModel이 초기화되지 않고 탭이 표시되지 않습니다. SettingsView 또는 ServersView로 전환해도 해당 뷰 모델이 초기화되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? Xamarin.Forms의 Caliburn Micro에서 처음입니다. 과거 WPF를 사용해 보았습니다. 우리가 갈 예제와 WPF 문서처럼 자세하지 않은 블로그가있는 것처럼 보이기 때문에 문서가 혼란 스럽습니다. 어떤 도움을 주시면 감사하겠습니다. 그게 도움이된다면 내 csproj와 project.json을 게시 할 수 있지만, 프로젝트 유형을 바꾸는 것을 주저하고있다. 나는 또 다른 대안은 PCL로 새 프로젝트를 만들고 그 프로젝트가 작동하는지 확인하는 것일까? 아이디어가 부족합니다. 어떤 도움을 주셔서 감사합니다!

답변

0

그래서 문제는 어셈블리를 사용할 프레임 워크를 말하지 않고 있다는 것이 었습니다. 기능 샘플은 공유 코드에 라이브러리를 사용하지 않습니다. 그래서 각각 iOS 및 안드로이드에 Application.cs하고 CaliburnAppDelegate.cs이 추가 :

protected override IEnumerable<Assembly> SelectAssemblies() 
{ 
    return this.GetAssemblies(); 
} 

이 내 클래스 라이브러리에서 만든 확장입니다 :

public static class Bootstrapper 
{ 
//... 

public static IEnumerable<Assembly> GetAssemblies(this object o) 
    { 
     IEnumerable<Assembly> assemblies = 
     new[] 
     { 
      o.GetType().GetTypeInfo().Assembly, 
      typeof(ShellViewModel).GetTypeInfo().Assembly 
     }; 
     return assemblies; 
    } 
//... 
} 

는이 문제를 해결합니다. 클래스 라이브러리를 사용하여 샘플을 연결하는 데 문제가있는 다른 사용자에게 도움이되기를 바랍니다. 그런데 설치 샘플과 비교할 때 이것을 알아 냈습니다.