How to use ViewModelCloser to close the View of the ViewModel?
c#, mvvmcross, xamarin
Solution
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 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.
I realise this is 'more work' than was required in vNext, but hopefully it's a more flexible, powerful approach.
Problem
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?