本文介绍了在 mvvmcross 中显示来自非视图/视图模型的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 从非视图在 mvvmcross 中打开视图的正确方法是什么?在视图模型中,我们将使用 ShowViewModel(..).What is the correct way to open a View in mvvmcross from a non-view? From within a viewmodel we would use ShowViewModel<>(..).具体来说,我们正在响应打开应用程序(带有自定义负载)的推送通知,该通知指示应加载的视图.Specifically we are responding to a push notification opening the app (with a custom payload) which dictates a view that should be loaded.我们有一个 hackety 解决方法只是为了概念证明,只是想了解正确的 MVX 方法We have a hackety workaround just for proof of concept, just wanted to get an idea of the correct MVX approach推荐答案我认为没有正确的方法" - 我认为这取决于您的应用以及您需要它做什么.I don't think there is a 'correct way' - I think it depends on your app and what you need it to do.对于某些特定情况 - 例如ViewModel->ViewModel 和 AppStart - MvvmCross 提供了一些方便的方法:For some specific cases - e.g. ViewModel->ViewModel and AppStart - MvvmCross provides some convenient methods:你可以在MvxViewModel中调用ShowViewModel可以覆盖应用程序启动以使用提示对象 - 参见 https://speakerdeck.com/crillous/appstart-在-mvvmcross但总的来说,任何类都可以通过调用:But overall, any class can request a ShowViewModel by calling: var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>(); viewDispatcher.ShowViewModel(new MvxViewModelRequest( viewModelType, parameterBundle, presentationBundle, requestedBy));此外,还有一个基类 - MvxNavigatingObject.cs - 这可以帮助解决这个问题(它是 MvxViewModel 和 MvxAppStart 的基类) - 因此您可以轻松提供一个或多个服务,例如 INavigateMyselfService,其实现继承自 MvxNavigatingObject.Further, there is a base class - MvxNavigatingObject.cs - which can help with this (it's a base class of MvxViewModel and MvxAppStart) - so you can easily provide one or more services like INavigateMyselfService who's implementations inherit from MvxNavigatingObject. public interface INavigateMyselfService { void GoWild(string side); } public class NavigateMyselfService : MvxNavigatingObject , INavigateMyselfService { public void GoWild(string side) { ShowViewModel<WildViewModel>(new { side = side }); } } 这篇关于在 mvvmcross 中显示来自非视图/视图模型的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 19:11