This repository was archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
INavigationService
Mark Smith edited this page Aug 29, 2016
·
4 revisions
The INavigationService
provides a simple abstraction for a navigation service usable with Xamarin.Forms. This allows a View Model to drive navigation based on commands or property changes.
The pages are identified using string-based keys and must be registered in the app somewhere (typically in the App
constructor).
-
RegisterPage
: registers aPage
with a string-based key. -
UnregisterPage
: removes a page from the registration DB. -
NavigateAsync
: navigates to a page specified by the string-based key. Can optionally provide theBindingContext
. -
CanGoBack
: Returns true/false if a page is on the back-navigation stack. -
GoBackAsync
: Pops the firstPage
off the back-navigation stack and displays it. -
PushModalAsync
: Pushes a new page onto the modal stack using the page-based key. Can optionally provide theBindingContext
. -
PopModalAsync
: Pops the firstPage
off the modal stack and displays it.
/// <summary>
/// Interface to manage navigation in the application.
/// </summary>
public interface INavigationService
{
/// <summary>
/// Register a Forms page with a key.
/// </summary>
/// <param name="pageKey">Page key (string).</param>
/// <param name="creator">Creator function to return a Page.</param>
void RegisterPage(string pageKey, Func<Page> creator);
/// <summary>
/// Unregister a known page from the navigation system.
/// </summary>
/// <param name="pageKey">Page key.</param>
void UnregisterPage(string pageKey);
/// <summary>
/// Navigate to a page using the known key.
/// </summary>
/// <returns>The async.</returns>
/// <param name="pageKey">Page key.</param>
/// <param name="viewModel">View model.</param>
Task NavigateAsync(string pageKey, object viewModel = null);
/// <summary>
/// Returns true/false whether we can go backwards on the Nav Stack.
/// </summary>
/// <value><c>true</c> if can go back; otherwise, <c>false</c>.</value>
bool CanGoBack { get; }
/// <summary>
/// Pops the last page off the stack and navigates to it.
/// </summary>
/// <returns>Async response</returns>
Task GoBackAsync();
/// <summary>
/// Push a page onto the modal stack.
/// </summary>
/// <returns>Async response</returns>
/// <param name="pageKey">Page key.</param>
/// <param name="viewModel">View model.</param>
Task PushModalAsync(string pageKey, object viewModel = null);
/// <summary>
/// Pops the last page off the modal stack
/// </summary>
/// <returns>Async response</returns>
Task PopModalAsync();
}