MvvmCross-构建共享的视图模型和视图 [英] MvvmCross - structuring shared View Models and Views

查看:85
本文介绍了MvvmCross-构建共享的视图模型和视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,都喜欢这个框架.

Love this framework thus far.

也就是说,打了我的第一个路障.我创建了一个基于MvvmCross的库(实际上是几个库),该库执行将在同一家族的多个跨平台应用程序中使用的登录服务.我还不太清楚是如何将这些登录库插入我的其他应用程序(也将使用MvvmCross).我希望能够在这些应用程序中重复使用相同的ViewModel和视图.

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.

假设我已经阅读并观看了很多slodge的视频. :)都很好.

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

我认为具有两个核心库的MvvmCross 与我最接近的东西有关在尝试做,这只是将MvvmCross项目粉碎在一起,并使它们神奇地起作用.但是在那篇代码示例中存在一些不一致之处的这篇文章中,我一直无法使它正常工作.

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.

推荐答案

安装程序中有2种方法告诉mvvmcross在何处查找Views和ViewModels.如果您覆盖这些内容,则系统应找到您的视图和视图模型.

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:

  • 为wp提供更多帮助,以查找其他程序集中的任何视图的xaml网址-默认情况下,mvx仅在/views中查找xaml uri,而不在任何其他程序集的任何其他文件夹中查找.提供xaml网址的一种方法是在View的c#文件中添加MvxPhoneViewAttribute,另一种方法是覆盖
  • 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.

这篇关于MvvmCross-构建共享的视图模型和视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆