MvvmCross - structuring shared View Models and Views

☆樱花仙子☆ 提交于 2019-12-11 19:22:00

问题


Love this framework thus far.

That said, hit my first roadblock. I have created an MvvmCross-based library (actually a few libraries) that performs login services that will be used across multiple cross-platform applications of the same family. What I can't quite figure out is how to plug these login libraries into my other applications (which will also be using MvvmCross). I want to be able to re-use the same ViewModels and Views across these apps.

Assume that I've read and watched a lot of slodge's videos. :) Which are very good.

I think MvvmCross with two core libraries was about the closest thing to what I'm trying to do, which is just smash MvvmCross projects together and make it all magically work. But going by that post, which had some inconsistencies in the code samples, I've been unable to get this working.


回答1:


There are 2 methods in Setup which tell mvvmcross where to look for Views and ViewModels. If you override these then the system should find your views and view models.

    protected virtual Assembly[] GetViewAssemblies()
    {
        var assembly = GetType().Assembly;
        return new[] {assembly};
    }

    protected virtual Assembly[] GetViewModelAssemblies()
    {
        var app = Mvx.Resolve<IMvxApplication>();
        var assembly = app.GetType().Assembly;
        return new[] {assembly};
    }

Beyond this, the only additions to this that I'm aware of are that you might need:

  • to give wp some extra help in finding the xaml urls for any views which are in additional assemblies - by default mvx only looks for the xaml uri in /views, not in any other folder in any other assembly. One way to provide the xaml urls is to add a MvxPhoneViewAttribute within the View's c# file, another is to override the MvxPhoneViewsContainer to make it provide custom urls.
  • to adjust some of the android project settings in order to get resources shared from libraries to main project (although this functionality has gotten much better within xamarin.android this year.


来源:https://stackoverflow.com/questions/17199625/mvvmcross-structuring-shared-view-models-and-views

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!