简体   繁体   English

在MvvmCross中将参数从ViewModel传递到ViewModel的替代方法

[英]Alternatives on passing parameters from ViewModel to ViewModel in MvvmCross

We are at the preparation on porting a huge windows mobile app to Xamarin and we are using MvvmCross to help us with the Mvvm. 我们正在准备将大型Windows移动应用程序移植到Xamarin,我们正在使用MvvmCross帮助我们使用Mvvm。

The application is huge, where workflows live between several pages. 该应用程序非常庞大,工作流位于多个页面之间。 So there is a need to pass states/objects between pages. 因此,需要在页面之间传递状态/对象。 As those states can be big, it does not make sense to serialise them between navigation calls. 由于这些状态可能很大,因此在导航调用之间序列化它们是没有意义的。

My question is: what are any proven or used alternatives to pass objects between view models? 我的问题是:在视图模型之间传递对象的任何经过验证或使用的替代方法是什么? Is there some session manager? 有会议管理器吗?

Note: we are starting with Android, so maybe there is also good an Android only solution. 注意:我们从Android开始,所以也许还有一个很好的Android解决方案。

Hint: I posted this question on Programmers as well, not sure what's the better platform for this: https://softwareengineering.stackexchange.com/questions/285219/alternatives-on-passing-parameters-from-viewmodel-to-viewmodel-in-mvvmcross 提示:我也在程序员上也发布了这个问题,不确定是否有更好的平台: https : //softwareengineering.stackexchange.com/questions/285219/alternatives-on-passing-parameters-from-viewmodel-to-viewmodel-在-mvvmcross

A couple of options I use are: 我使用的几个选项是:

1) Persist state to a SQLite database and pass an identifier from ViewModel to ViewModel. 1)将状态保留到SQLite数据库,并将标识符从ViewModel传递到ViewModel。 This is simple and ensures that the state remains even between app restarts. 这很简单,可以确保即使在应用重新启动之间也保持该状态。

2) Another option, which is useful in a wizard-like setting is to use a Cache service. 2)在类似于向导的设置中有用的另一个选项是使用缓存服务。 I simply created an interface to add and remove entries in a cache by key. 我只是创建了一个接口,用于按键添加和删除缓存中的条目。 I treat it like a standard MvvmCross service and use IoC to inject into my view models. 我将其视为标准的MvvmCross服务,并使用IoC注入到我的视图模型中。 At the start of the process, create a GUID to use as your key, add your state to the cache. 在该过程的开始,创建一个GUID用作密钥,然后将状态添加到缓存中。 Simply pass the key to the next view model, where it can retrieve the state from cache. 只需将密钥传递给下一个视图模型,即可从缓存中检索状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM