在MvvmCross v3的CustomerManagement示例中,方法
void RequestClose(IMvxViewModel viewModel)
会关闭顶部View
。那么如何关闭ViewModel
的View
呢?我不建议使用那个ViewModelCloser方法 - 尽管如果您想要可以扩展它。
MvvmCross v3已经移除了之前的CloseViewModel方法 - 因为它不能在所有平台和所有呈现风格中正常工作 - 无论是在导航控制器、分割视图、选项卡、弹出窗口、对话框等中。
为了替代它,v3引入了一个新的ViewModel调用:
protected bool ChangePresentation(MvxPresentationHint hint)
在UI中,这与IMvxViewPresenter方法匹配:
void ChangePresentation(MvxPresentationHint hint);
要使用此功能,您需要:
Create a new Hint class - e.g. public class CustomPresentationHint : MvxPresentationHint { /* ... */ }
In each UI project, provide a custom presenter (normally by overriding CreateViewPresenter()
in your Setup.cs
class) - and in that custom presenter handle the ChangePresentationHint
call:
public void ChangePresentation(MvxPresentationHint hint)
{
if (hint is CustomPresentationHint)
{
// your custom actions here
// - which may involve interacting with the RootFrame, with a NavigationController, with the AndroidFragment manager, etc
}
}
In your viewmodel, you can send a CustomPresentationHint
when you want to.
CusomPresentationHint
中添加一个public IMvxViewModel ViewModelToClose {get;set;}
属性。 - Stuart