Array

Handling Navigation Requests

Must Read

Brainstorming, Surveying, and Reviewing Promotional Material

Try to think as your target market would if they were to do a search for information on a...

Effective Debt Repayment With Direct Student Loan Consolidation

College students normally take in student loans to pay for their university or college education. However, eventually, these students...

Eliminate Debts Cheaply Through Secured Debt Consolidation Loans

If you think it is high time that you pay off all those debts, otherwise you may be inviting...

An Easier Way of Getting A Roof Over Your Head

One of the biggest investments that an individual may have is his home. A home is where you relax...

Graduate’s $200,000 Student Loan Debt Spurs New Website

The Northeastern University graduate figures that without help, she'll never be able to repay the nearly $190,000 in private...

Student Loan Consolidation Rates – Vital Factors To Consider Before You Make a Decision

Student loan consolidation rates are often among the very top concerns of someone who finds themselves under the load...
Admin
test

In addition to invoking commands from the view, the Tailspin mobile client also triggers navigation requests from the view. These requests could be to navigate to a particular view or navigate back to the previous view. In some scenarios, for example if the application needs to navigate to a new view when a command completes, this requires the view model to send a message to the view. In other scenarios, you might want to trigger the navigation request directly from the view
without involving the view model directly. When you’re using the MVVM pattern, you want to be able to do all this without using any code-behind in the view, and without introducing any dependency on the view implementation in the view model classes.

Inside the Implementation

The following code example from the FilterSettingsView.xaml file shows two examples of initiating navigation in the sample application.

XAML
<i:Interaction.Behaviors>
<prismInteractivity:ApplicationBarButtonCommand
ButtonText=”Save” CommandBinding=”{Binding SaveCommand}”/>
<prismInteractivity:ApplicationBarButtonNavigation
ButtonText=”Cancel” NavigateTo=”#GoBack” />

</i:Interaction.Behaviors>

The first example invokes the SaveCommand command in the view model. The code that implements this command causes the application to navigate back to the previous view if the command succeeds, so in this example, the navigation is initiated from the view model. The following code example from the FilterSettingsView Model class illustrates this.

C#
public DelegateCommand SaveCommand { get; set; }

public FilterSettingsViewModel(…)
{

this.SaveCommand =
new DelegateCommand(this.Submit, () => !this.CanSubmit);

}

public void Submit()
{

this.NavigationService.GoBack();

}

public bool CanSubmit
{
get { return this.canSubmit; }
set
{
if (!value.Equals(this.canSubmit))
{
this.canSubmit = value;
this.RaisePropertyChanged(() => this.CanSubmit);
}
}
}

The second example shows how the view can initiate the navigation directly by navigating back to the previous view (in this case, the SurveyListView page) without executing a command.

Both examples use the ApplicationFrameNavigationService class shown in the following code example to perform the navigation.

C#
public class ApplicationFrameNavigationService :
INavigationService
{
private readonly PhoneApplicationFrame frame;

public ApplicationFrameNavigationService(
PhoneApplicationFrame frame)
{
this.frame = frame;
}
public bool Navigate(Uri source)
{
return this.frame.Navigate(source);
}
public void GoBack()
{
this.frame.GoBack();
}
public bool CanGoBack
{
get { return this.frame.CanGoBack; }
}
public Uri CurrentSource
{
get { return this.frame.CurrentSource; }
}
}

This class, which implements Tailspin’s INavigationService interface, uses the phone’s PhoneApplicationFrame instance to perform the navigation request for the application.

A view model can invoke the Navigate method on the Application FrameNavigationService object to cause the application to navigate to a particular view in the application or the GoBack method to return to the previous view.

The ViewModel base class maintains the INavigationService instance for all the view models, and the Funq dependency injection container is responsible for initially creating the Application FrameNavigationService object that implements this interface.

To avoid any code-behind in the view when the view initiates the navigation, the developers at Tailspin use an interaction behavior from the Prism Library. The following code example shows how the Cancel button is declared in the FilterSettingsView.xaml file.

XAML
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar …>

<shell:ApplicationBarIconButton Text=”Cancel”
IconUri=”…”/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<i:Interaction.Behaviors>

<prismInteractivity:ApplicationBarButtonNavigation
ButtonText=”Cancel” NavigateTo=”#GoBack” />

</i:Interaction.Behaviors>

The ApplicationBarButtonNavigation behavior object contains a reference to the view model, and the view model contains the reference to the ApplicationFrameNavigationService instance that handles the navigation request. The ApplicationBarButtonNavigation behavior object checks for the special value “#GoBack”, in which case, it uses the navigation service to navigate back to the previous view; otherwise, it uses the value of the NavigateTo attribute to identify the view to navigate to.

Previous articleCommands
Next articleUser Interface Notifications

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place at the...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when was the...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial as well...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though he had...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost everyone needs...

More Articles Like This