Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SunboX/Prism.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBart Lannoeye <bart.lannoeye@gmail.com>2016-11-23 20:22:07 +0300
committerGitHub <noreply@github.com>2016-11-23 20:22:07 +0300
commitd101cc294e7070c955e7969851b34d0dcca6c5e9 (patch)
treeb352a8cdcd14cb120b9f2274b2a968e245004d60 /docs
parent838f7cebc0ea40e87a7e515a60ac4a9070d84cb5 (diff)
RTD 03 Navigation Service: fixing H1
Diffstat (limited to 'docs')
-rw-r--r--docs/Xamarin-Forms/3-Navigation-Service.md19
1 files changed, 12 insertions, 7 deletions
diff --git a/docs/Xamarin-Forms/3-Navigation-Service.md b/docs/Xamarin-Forms/3-Navigation-Service.md
index 59882bc..54939b4 100644
--- a/docs/Xamarin-Forms/3-Navigation-Service.md
+++ b/docs/Xamarin-Forms/3-Navigation-Service.md
@@ -1,4 +1,4 @@
-#Using the Navigation Service
+#Using the Navigation Service
Navigating in a Prism application is conceptually different than standard navigation in Xamarin.Forms. While Xamarin.Forms navigation relies on a Page class instance to navigate, Prism removes all dependencies on Page types to achieve loosely coupled navigation from within a ViewModel. In Prism, the concept of navigating to a View or navigating to a ViewModel does not exist. Instead, you simply navigate to an experience, or a unique identifier, which represents the target view you wish to navigate to in your application.
@@ -29,6 +29,7 @@ _navigationService.NavigateAsync(new Uri("MainPage", UriKind.Relative));
//absolute
_navigationService.NavigateAsync(new Uri("http://www.brianlagunas.com/MainPage", UriKind.Absolute);
```
+
_Note: An absolute URI resets the navigation stack regardless of where you call it. It is equivalent to `Application.Current.MainPage = new MainPage()`_
**Important:** If you do not register your Pages with Prism, navigation will not work.
@@ -48,6 +49,7 @@ Next, use the `RegisterTypeForNavigation<T>` extension method off of the current
#### Default Registration
By default, **RegisterTypeForNavigation** will use the **Name** of the Page type as the unique identifier/key. The following code snippet results in a mapping between the MainPage type, and the unique identifier/key of "MainPage". This means when you request to navigate to the MainPage, you will provide the string "MainPage" as the navigation target.
+
```
protected override void RegisterTypes()
{
@@ -83,20 +85,23 @@ _navigationService.GoBackAsync();
## Passing parameters
The Prism navigation service also allows you to pass parameters to the target view during the navigation process. Passing parameters to the next View can be done using an overload of the **INavigationService.NavigateAsync** method. This overload accepts a **NavigationParameters** object that can be used to supply data to the next View. The **NavigationParameters** object is in fact just a dictionary. It can accept any arbitrary object as a value.
-```
+```cs
var navigationParams = new NavigationParameters ();
navigationParams.Add("model", new Contact ());
_navigationService.NavigateAsync("MainPage", navigationParams);
```
You can also create an HTML query string to generate your parameter collection.
-```
+
+```cs
var queryString = "code=CR&desc=Red";
var navigationParams = new NavigationParameters(queryString);
_navigationService.NavigateAsync("MainPage", navigationParameters);
```
+
When using a Uri to navigate, you may append the Uri with parameters, which will be used as the navigation parameters.
-```
+
+```cs
//query string
_navigationService.NavigateAsync(new Uri("MainPage?id=3&name=brian", UriKind.Relative));
@@ -109,14 +114,14 @@ navParameters.Add("name", "brian");
_navigationService.NavigateAsync(new Uri("MainPage?id=3", UriKind.Relative), navParameters);
```
-
Getting to this data in the target View that is being navigated to, can be achieved by using the **INavigationAware** interface on the corresponding ViewModel.
## INavigationAware
The ViewModel of the target navigation Page can participate in the navigation process by implementing the **INavigationAware** interface. This interface adds two methods to your ViewModel so you can intercept when the ViewModel is navigated to, or navigated away from.
Example:
-```
+
+```cs
public class ContactPageViewModel : INavigationAware
{
private Contact _contact;
@@ -136,7 +141,7 @@ public class ContactPageViewModel : INavigationAware
## IConfirmNavigation
A ViewModel can determine whether or not it can perform a navigation operation. When a ViewModel implements the **IConfirmNavigation** or the **IConfirmNavigationAsync** interface, the navigation process looks to see what the result of this method is. If _true_, a navigation process can be invoked, meaning a call to `NavigationService.NavigateAsync("target")` can be made. If _false_, the ViewModel cannot invoke the navigation process.
-```
+```cs
public class ContactPageViewModel : IConfirmNavigation
{
public bool CanNavigate(NavigationParameters parameters)