MvvmLight Navigation Extension
When navigating in iOS we can choose to do a modal navigation. That means that we open a page that is on top of the other pages and not included in the navigation stack. When using MvvmLight we only have one method (NavigateTo) when we want to open a new page.
While I want to use MvvmLight and open "modals" I have created a MvvmLight extension for iOS (for storyboards only in this pre version) and Android, https://www.nuget.org/packages/MvvmLightNavigationServiceExtension. If you're interested in the source, it will be at GitHub, https://github.com/dhindrik/MvvmLightNavigationExtension.
While this is a pre release, feedback is very welcome!
Using the extension from shared code
To use it in your ViewModels you need to add the namespace to the class.
var navigation = ServiceLocator.Current.GetInstance(); navigation.OpenModal("Page2");
We will configure the NavigationService in same way as when we using NavigationService from MvvmLight but we using NavigationServiceExtension() instead of NavigationService and our instance of NavigationServiceExtension should be registered to both INavigationService and INavigationServiceExtension.
var nav = new MvvmLightNavigationExtension.iOS.NavigationServiceExtension(); nav.Initialize((UINavigationController)Window.RootViewController); nav.Configure("Page1", "MainView"); nav.Configure("Page2", "PageView"); container.RegisterInstance(nav); container.RegisterInstance(nav);
var nav = new MvvmLightNavigationExtension.Droid.NavigationServiceExtension(); nav.Initialize(): nav.Configure("Page1", "MainView"); nav.Configure("Page2", "PageView"); container.RegisterInstance(nav); container.RegisterInstance(nav);