在 mvvmcross 中显示来自非视图/视图模型的视图

编程入门 行业动态 更新时间:2024-10-19 16:27:18
本文介绍了在 mvvmcross 中显示来自非视图/视图模型的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

从非视图在 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
  • 可以覆盖应用程序启动以使用提示对象 - 参见 speakerdeck/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 中显示来自非视图/视图模型的视图

本文发布于:2023-11-26 18:09:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634632.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   模型   mvvmcross

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!