问题
In the MvvmCross v3, CustomerManagement example, the method void RequestClose(IMvxViewModel viewModel) closes the top View. How do you close the View of a ViewModel instead?
回答1:
I wouldn't use that ViewModelCloser method - although it could be extended if you want to.
MvvmCross v3 removed the previous CloseViewModel method - because it didn't really work across all platforms and across all presentation styles - across all of navigation controllers, splitviews, tabs, flyouts, popups, dialogs, etc.
To replace it, v3 introduces a new ViewModel call:
protected bool ChangePresentation(MvxPresentationHint hint)
This is matched in the UIs with an IMvxViewPresenter method:
void ChangePresentation(MvxPresentationHint hint);
To use this, you will need to:
Create a new Hint class - e.g.
public class CustomPresentationHint : MvxPresentationHint { /* ... */ }In each UI project, provide a custom presenter (normally by overriding
CreateViewPresenter()in yourSetup.csclass) - and in that custom presenter handle theChangePresentationHintcall: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
CustomPresentationHintwhen you want to.
I realise this is 'more work' than was required in vNext, but hopefully it's a more flexible, powerful approach.
来源:https://stackoverflow.com/questions/15919288/how-to-use-viewmodelcloser-to-close-the-view-of-the-viewmodel