2017-01-16 26 views
0

在Xamarin Forms應用程序中,我想提供另一個視圖程序集(默認的程序集),其中MvvmCross可以查找視圖。向MvvmCross提供其他視圖程序集

以下MvvmCross Wiki,在UWP的設置下課後,我override GetViewAssemblies()添加額外的組件:

protected override IEnumerable<Assembly> GetViewAssemblies() 
    { 
     var viewAssemblies = new List<Assembly>(); 
     viewAssemblies.AddRange(base.GetViewAssemblies()); 
     viewAssemblies.Add(typeof(MovementPage).GetTypeInfo().Assembly); 

     return viewAssemblies; 
    } 

但應用抱怨,它無法找到視圖:

mvx:Diagnostic: 10.46 Setup: Secondary end 
mvx:Diagnostic: 10.51 Showing ViewModel MovementViewModel 
Exception thrown: 'System.Collections.Generic.KeyNotFoundException' in MvvmCross.Core.dll 
mvx:Diagnostic: 10.82 Page not found for MovementPage 
mvx:Error: 10.84 Skipping request for MovementViewModel 
Exception thrown: 'System.ArgumentNullException' in Xamarin.Forms.Platform.UAP.dll 
Exception thrown: 'System.ArgumentNullException' in MovementTimer.UWP.exe 

當這頁面出現在默認程序集(包含ViewModels,App.cs的程序集)中,頁面顯示。

這裏可以做些什麼?

+0

我做這樣才能把觀點與業務邏輯在不同的組件。 – Anil

回答

0

重寫InitializeViewLookup()的作品,但它是乏味:(

protected override void InitializeViewLookup() 
{ 
    var viewsLookup = new Dictionary<Type, Type> 
    { 
     [typeof(MovementViewModel)] = typeof(MovementPage) 
    }; 

    var container = Mvx.Resolve<IMvxViewsContainer>(); 
    container.AddAll(viewsLookup); 
} 
相關問題