为MvvmCross提供额外的View程序集

3
在Xamarin Forms应用中,我想提供另一个View程序集(而不是默认的程序集),让MvvmCross可以查找视图。
按照MvvmCross Wiki的说明,在UWP的Setup类中,我重写了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的程序集),则该页面将被显示。
这里可以做什么?

我这样做是为了将视图和业务逻辑放在不同的程序集中。 - Anil
1个回答

0

覆盖 InitializeViewLookup() 是可行的,但是很繁琐 :(

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

    var container = Mvx.Resolve<IMvxViewsContainer>();
    container.AddAll(viewsLookup);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接