MVVMbasics Logo

mobilemotion.eu Logo


Back to Class Reference home page


MVVMbasics.Services
Class NavigatorService

MVVMbasics.Services.INavigatorService
  implemented by MVVMbasics.Services.NavigatorService
 

 
[MvvmService]
public class NavigatorService : INavigatorService

Service which provides page / window navigation functionality. Includes both "standard" navigation methods which navigate backwards as well as a View-/Viewmodel-Locator that stores mappings of View to Viewmodel and allows to directly navigate to a View that is associated with a given Viewmodel.


Method Summary
void  Register<T>(object view) where T : BaseViewmodel
Registers a mapping of Viewmodel to View.
void  RegisterAll(Assembly assembly = null)
Traverses all Views and registers all that provide a MvvmNavigationTarget attribute.
void  RegisterAll(string ns, Assembly assembly = null)
Traverses all Views that are located within a given namespace and registers all that provide a MvvmNavigationTarget attribute.
object  Retrieve<T>() where T : BaseViewmodel
Returns a View or throws an exception if no matching View has been registered.
void  NavigateTo<T>(params Parameter[] parameters) where T : BaseViewmodel
Retrieves a View and navigates to the corresponding page / window.
void  NavigateTo<T>(string key, object value) where T : BaseViewmodel
Retrieves a View and navigates to the corresponding page / window, passing one parameter.
void  NavigateTo<T>(ParameterList parameters) where T : BaseViewmodel
Retrieves a View and navigates to the corresponding page / window.
void  NavigateBack()
Navigates to the last View on the back stack.
void  SetBackParameters(params Parameter[] parameters)
Stores parameters to be passed to the previous View on the next backward navigation event.
void  SetBackParameters(string key, object value)
Stores one parameter to be passed to the previous View on the next backward navigation event.
void  SetBackParameters(ParameterList parameters)
Stores parameters to be passed to the previous View on the next backward navigation event.
void  ClearBackParameters()
Removes parameters which have been stored to be passed to the previous View on the next backward navigation event.
bool  CanGoBack()
Checks whether a backwards navigation is possible or not (the latter ist the case if the current View is the Application's main View).
void  RemoveBackEntry()
Removes the previously shown View from the back stack.
void  ClearBackStack()
Removes all entries from the back stack.
 
Method Detail

Register<T>

public void Register<T>(object view) where T : BaseViewmodel

Registers a mapping of Viewmodel to View. Viewmodel must be supplied as Type object, View must be supplied as Uri object. The Viewmodel type must be a subtype of BaseViewmodel. Exceptions will be thrown if this type constraints is not fulfilled, or if a mapping with the specified Viewmodel type exists already.


RegisterAll

public void RegisterAll(Assembly assembly = null)

Traverses all Views and registers all that provide a MvvmNavigationTarget attribute. An exception is thrown if one of the traversed Views references a Viewmodel type that has been registered already.

Parameters:

assembly - Assembly to be scanned. If NULL, the calling assembly will be scanned.


RegisterAll

public void RegisterAll(string ns, Assembly assembly = null)

Traverses all Views that are located within a given namespace inside a given assembly and registers all that provide a MvvmNavigationTarget attribute. An exception is thrown if one of the traversed Views references a Viewmodel type that has been registered already.

Parameters:

ns - Namespace to be scanned. If ends with '.*', also sub-directories will be scanned. If NULL, the whole assembly will be scanned.
assembly - Assembly to be scanned. If NULL, the calling assembly will be scanned.


Retrieve<T>

public object Retrieve<T>() where T : BaseViewmodel

Returns a View or throws an exception if no matching View has been registered.


NavigateTo

public void NavigateTo<T>(params Parameter[] parameters) where T : BaseViewmodel

Retrieves a View and navigates to the corresponding page / window.


NavigateTo

public void NavigateTo<T>(string key, object value) where T : BaseViewmodel

Retrieves a View and navigates to the corresponding page / window, passing one parameter.


NavigateTo

public void NavigateTo<T>(ParameterList parameters) where T : BaseViewmodel

Retrieves a View and navigates to the corresponding page / window.


NavigateBack

public void NavigateBack()

Navigates to the last View on the back stack.


SetBackParameters

public void SetBackParameters(params Parameter[] parameters)

Stores parameters to be passed to the previous View on the next backward navigation event.

Parameters:

parameters - Parameters to be stored for passing to the previos View.


SetBackParameters

public void SetBackParameters(string key, object value)

Stores one parameter to be passed to the previous View on the next backward navigation event.

Parameters:

key - Key of the parameter to be stored for passing to the previos View.
value - Value of the parameter to be stored for passing to the previos View.


SetBackParameters

public void SetBackParameters(ParameterList parameters)

Stores parameters to be passed to the previous View on the next backward navigation event.

Parameters:

parameters - Parameters to be stored for passing to the previos View.


ClearBackParameters

public void ClearBackParameters()

Removes parameters which have been stored to be passed to the previous View on the next backward navigation event.


ClearBackParameters

public void ClearBackParameters()

Removes parameters which have been stored to be passed to the previous View on the next backward navigation event.


CanGoBack

public bool CanGoBack()

Checks whether a backwards navigation is possible or not (the latter ist the case if the current View is the Application's main View).

Returns:

TRUE if a backwards navigation is possible, FALSE otherwise.


RemoveBackEntry

public void RemoveBackEntry()

Removes the previously shown View from the back stack.


ClearBackStack

public void ClearBackStack()

Removes all entries from the back stack.