Archivi tag: navigation

Xamarin Forms & .NET Standard: basic navigation

In the last post about Xamarin Forms we’ve started to see the basic concepts on how to begin the development of a cross-Platform application. In this post we’re going to explore some basic navigation concepts and some tips to organize our solution. Also, we’ll develop a simple CrossPlatformApp that welcomes us with a main screen and a button to navigate to a new view where we can generate a random integer. Continua a leggere Xamarin Forms & .NET Standard: basic navigation

Agile@School – quinta lezione

Oggi siamo giunti al giro di boa per all’IIS Viola/Marchesini di Rovigo col progetto Agile@School e Xamarin: quinta lezione su dieci.

Il clima natalizio si è sentito e gli studenti erano tutti di buon umore e carichi.


Continua a leggere Agile@School – quinta lezione

Prism UWP for beginners: navigation

In this post we’ll talk about the navigation with Prism in UWP. With navigation I mean the technique to go from one page to another of your app. The operation in UWP/XAML is tipically performed with the Frame class that’s available only in the code-behind of a Page because it inherits from Frame. This way we do not respect the MVVM pattern. Prism comes in our help providing a wrapper to the Frame class accessible from the ViewModel: it’s the NavigationService. This isn’t a very new name to us because we found it in the bootstrapper.

protected override Task OnInitializeAsync(IActivatedEventArgs args)

We saw it at the end of the bootstrap procedure in the OnLaunchApplicationAsync method, too.

protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
NavigationService.Navigate(PageNames.Main.ToString(), null);
return Task.FromResult(true); //This is a little trick because this method returns a Task.

To try the navigation system we create a SettingsPage in the View folder and then we’ll navigate to that page with a button in the MainPage.


To go to there we need a command in the MainPageViewModel class and bind it in the MainPage view.

public class MainPageViewModel : ViewModelBase
public DelegateCommand GoToSettings { get; private set; }


In the constructor we initialize the GoToSettings property.

public MainPageViewModel(ITwitterService twitterService, IWeatherService weatherService, INavigationService navigationService)

_navigationService = navigationService;

GoToSettings = new DelegateCommand(() =>
_navigationService.Navigate("Settings", null);

In the constructor we added a parameter: the INavigationService reference. This new dependency will be handled by Unity container when resolving an instance of MainPageViewModel. The GoToSettingsCommand is composed by a single line of code where we call the Navigate method with the first argument that is the name of the page where we want to go and the second argument is to add additional information: since we have no additional data we write null.

In this example the Settings page allows us to change the backgorund image of the main page. We notice that in the upper left corner of the application a back. This is handeld by the UWP framwork when detects a navigation.

This back button can be different based on the device where the app is running: phone, tablet or pc. For example in a tablet with tablet mode enabled it will appear on the navigation bar at the botton of the device. In the MSDN we can find al the details.


When we click the back button we go back to the main page.

When navigating in our view-model we can use two methods to detect when we land into a page or when we leave a page. OnNavigatedTo is callaed when navigation in performed to a page. OnNavigatingFrom is called when navigating away from the page.

   public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary viewModelState)
            base.OnNavigatedTo(e, viewModelState);

//Loading state custom logic.

        public override void OnNavigatingFrom(NavigatingFromEventArgs e, Dictionary viewModelState, bool suspending)
            base.OnNavigatingFrom(e, viewModelState, suspending);
//Save state logic.


In this post we explored the basic concept about navigating with Prism in UWP App with the Navigation Service and the events that Prism offers to detect the transition from one page to another.

If you want to learn more you can refer to the Prism official website and MSDN. Happy coding!

Prism UWP posts