问题描述
我有两个关于 MvvMCross 导航的问题.
I have two questions regarding navigation in MvvMCross.
- 如何返回导航堆栈上的视图模型?分别:如何返回指定数量的视图模型?
如何截断导航堆栈?
- How can I go back to a view model, that is on the navigation stack? Respectively: How can I go back a specified number of view models?
How can I truncate the navigation stack?
例如:A|B|C 在堆栈上,导航到 D 使堆栈看起来像:D
e.g: A|B|C on the stack, navigating to D makes the stack look like: D
推荐答案
操作后台堆栈的功能是特定于平台和应用程序的 - 例如:
The functionality for manipulating the back stack is platform and app specific - e.g:
- 操作 Android Activity backstack 与操作 iOS UINavigation 控制器非常不同
- 这取决于您的应用是否使用标签、活动、片段、弹出窗口、模态、汉堡菜单等
因此,像这样的 UI 更改的实际实现并未在 MvvmCross 中定义.
Because of this, the actual implementation of UI changes like this is not defined within MvvmCross.
相反,由您在应用程序中实现 presenter
.
Instead, it's up to you to implement in your applications presenter
.
您需要遵循的基本流程是:
The basic flow you'll need to follow is:
弄清楚你的应用结构是什么以及你想要达到什么效果
Work out what your app structure is and what effect(s) you want to achieve
为了这个效果,声明一个自定义的呈现提示 - 例如
For this effect, declare a custom presentation hint - e.g
public class MyFunkyPresentationHint : MvxPresentationHint
{
public int DegreeOfFunkiness { get; set; }
}
- 您可以从任何 ViewModel 创建和发送此提示
base.ChangePresentation(new MyFunkyPresentationHint() { DegreeOfFunkiness=27 });
- 在您的自定义演示者中,您可以进行您想要的后台屏幕破解:
public override void ChangePresentation(MvxPresentationHint hint)
{
if (hint is MyFunkyPresentationHint)
{
// your code goes here
return;
}
base.ChangePresentation(hint);
}
有关自定义演示者的示例,请参阅:http://slodge.blogspot.com/2013/06/presenter-roundup.html
有关 backstack 操作的一个示例,请参阅在某些标准演示器中如何实现 Close(this)
.
For one example of backstack manipulation, see how Close(this)
is implemented in some of the standard presenters.
这篇关于MvvMCross 导航回多个视图模型/截断导航堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!