I am using a custom view presenter in my Windows Store app.
I show a SettingsFlyout and in its SettingsViewModel view-model I have a command bound to a button on the flyout which needs to hide the flyout (SettingsFlyout::Hide()).
For this, I have different options:
in the SettingsFlyout, I can handle the button click
in the ICommand in the view-model, send a message from view-model to view
in the ICommand in the view-model, call
Close(this)
.I was trying to implement last one, using Close(this) in the view-model.
For this, in the custom view presenter I was thinking to handle
ChangePresentation(MvxPresentationHint hint)
orClose(IMvxViewModel viewModel)
.But I don't see how to get the view instance corresponding to the view-model instance.
In my case I have the SettingsViewModel instance and I need to get the instance of the displayed SettingsFlyout.
Is there a way?
This is a custom presentation/navigation, so this is left open to the individual app to implement.
Some possible ideas are:
ViewModel
/DataContext
property) - if doing this, be careful to remove each View from this list when they are closed otherwise this could cause horrible memory leaks.SettingsFlyout
class could itself just have aCurrent
static member - or could call a singleton service which stores theCurrent
(if needed this could be archicted into a more general solution - beyond just the SettingsFlyout)Closed
mechanism could be a custom event or property fired from your SettingsFlyoutViewModel to your SettingsFlyoutView - instead of using a NavigationHint.