Over the last month-and-a-half, I have been busting my butt trying to get Prism for Xamarin.Forms ready for prime time.   Since the first preview release back on Dec 3rd, I have release two more previews.  Today’s newest release is Prism for Xamarin.Forms 6.2.0 Preview 3.  This preview has a lot of improvements and some major changes which won’t break you know, but they will when it RTM’s.

With this preview we have support for the following containers:

A New Bootstrapping Process – Yet Again!

So, after a ton of iterations, limited accessibility of native Xamarin.Forms features, and feedback from the community, it became obvious that the bootstrapping process as it existed just wouldn’t work anymore.  In this latest preview, we had to move to a base application class.  So this means that the Bootstrapper is out, and the PrismApplication is in.  All the concepts are the same, but now instead of creating a Bootstrapper, you simply change your App.cs base class to derive from PrismApplication.

public class App : PrismApplication
{
    protected override void OnInitialized()
    {
        NavigationService.Navigate("MainPage");
    }

    protected override void RegisterTypes()
    {
        Container.RegisterTypeForNavigation<MainPage>();
    }
}

Now, if you modified your application to have an App.xaml and App.xaml.cs, then your App.xaml.cs will require you to move your call to InitializeComponent() from the App constructor to the OnInitialized() method before you navigate to your main view.  So your new App.xaml.cs would look like this:

public class App : PrismApplication
{
    protected override void OnInitialized()
    {
        InitializeComponent();
        NavigationService.Navigate("MainPage");
    }
}

This will ensure that all your application resources are available when you navigate to the main view in your application.

For now, both the Prism.Unity.Forms, and the Prism.Ninject.Forms have a class named PrismApplication.  I am considering changing the name f this class to be specific to each container.  For example, I am considering changing the names to PrismUnityApplication, and PrismNinjectApplication respectively.

What do you think about that?

Deep Linking Change

There was a small change to the behavior of deep linking.  Prior to Preview 3, if you were to provide a navigation URI with two or more segments (target pages) like this:

_navigationService.Navigate(“MyMasterDetail/MyNavigationPage/ViewA/MyTabbedPage/ViewB”);

Then the navigation service would automatically disable animating the page transitions.  This would essentially render the INavigationService.Navigate “animated” parameter useless, and if you tried to use it, the value you provided would have no impact on the behavior.  This is obviously not a good API design.  Start with Preview 3, if you are deep linking and do not want to animate the transition between the pages, you must manually specify the “animated” parameter.

_navigationService.Navigate(“MyMasterDetail/MyNavigationPage/ViewA/MyTabbedPage/ViewB”, animated: false);

Navigation Improvments

As with every release, there have been a number of improvements made to the navigation service logic.  The most noticeable improvement is with the INavigationService.GoBack() method.  The GoBack method is now smarter about the page you are on, and the page you are going back to regardless of the navigation stack the current page belongs to.

When navigating from a mAsterDetailPage, we now close the drawer automatically, which is a nice little feature that you don’t have to worry about anymore.

There is a new interface called IConfirmNavigationAsync which allows you to provide an async implementation of the existing IConfirmNavigation functionality.

The INavigationService methods now returns a Task for async/await scenarios for when you must await a navigation action before continuing your logic execution.

Providing an absolute URI for navigation will now replace the applications entire navigation stack.  Think of it as a reset, or clear all and start over type of navigation.

Summary

That about sums it up for this latest Prism for Xamarin.Forms Preview 3 release.  I wanted to get this preview out to the community as quickly as possible in order to get your feedback on the direction Prism for Xamarin.Forms is going.  Let me know what you think about the API.  Tell me what sucks, but better yet, tell me what is great.  If you have an idea that you would like to see implemented, be sure to fork our repository and submit a pull request.

As always, feel free contact me on my blog, connect with me on Twitter (@brianlagunas), or leave a comment below for any questions or comments you may have.

Brian Lagunas

View all posts

12 comments

  • hello,

    I really like where Prism is going cause I used it alot in the past with WPF and now I ma using it in Xam Forms, so really very good job

    I especially like the new navigation system you implemented but I have a few questions about it:

    1. is there a way to use viewmodel navigation with the deep linking features ?

    2. I have an app I am working on and it has a masterdetail page at one point which works but not exacly how I want it, to explain:
    – the app has a login page and a main page which don’t require a masterdetail page
    – after selecting something in the main page I need to go to a masterdetail page, the master page is a menu with a list and the details page is a navigation page which will have different other content pages as children depending what is clicked in the master page, and this is where I get confused:

    3. first off the layout gets all messed up since the app dosen’t know I swiched to a master/detail

    so the navigation goes something like this:

    – app strat :

    protected override void OnInitialized()
    {
    InitializeComponent();
    NavigationService.Navigate(“MainNavigationPage/LoginPage”);
    }

    – click on login button:

    _navigationService.Navigate(“MyMainPage”, navParams);

    – click on a button in the main page

    _navigationService.Navigate(“MyMasterDetailPage/MyNavigationPage/MyDetailsNewPage”);

    please check screenshots here https://drive.google.com/folderview?id=0BxnHizQV5zzKX0gzU29QLVdUbDQ

    4. you specified in the other blog post that the navigation system is smart and will know that I am in a master page and change the detail page but still keep the master (menu) page, I tried with different configurations but this is not happening :

    this is from the master viewmodel command

    _navigationService.Navigate(“MyMasterDetailPage/MyNavigationPage/MyNewDetailsNewPage”);
    //_navigationService.Navigate(“MyNavigationPage/MyNewDetailsNewPage”);
    //_navigationService.Navigate(“MyNewDetailsNewPage”);

    all the code above will bring up a new page over the previous one and not just change the details page (see screenshots above)

    5. how should the four pages (masterdetail, master, navigation and detail) look like in XAML and be linked from a viewmodel perspective ?

    for the example above the xaml page in the masterdetail page looks like:

    should I add a default details page as well ? and if so should it be contained in a navigation page ? something like:

    6. related to the one above, should there be a viewmodel for the masterdetail page ?

    7. is there a simple way to communicate with the viewmodels of the master and detail pages from the masterdetail viewmodel ?

    8. should the navigation be made from the masterdetail viewmodel or the master viewmodel ?

    9. I know you mentioned in a comment that pressing the back button in a masterdetail configuration will not cycle back throght the detail pages, can this be overriten ? because the master (menu) page links will be kind of a history of the detail pages that were open, when you hit the back button the one you are in gets deleted and you go to the previos one

    those are a lot of questions and maybe in the future you can add some documentation about it or an app example would be very nice

    thank you in advance

    Sergiu

    PS I will try today to make a prototype app with the problems above so it would be easier to understand

  • PPS my XAML got removed from question 5, also all my new lines and spaces … 🙁 I will make that app prototype and post again

  • Hi Brian,
    Like Prism! It has cool features. so UWP support is added in this Pre3 release, correct? if yes, when will we get a stable version of it.

  • Hello Brian,

    When is planned to be released Prism for Xamarin.Forms 6.2.0? We are starting a new project and I would like to implement the latest version of PRISM.

    Really awesome library and work you have done. Thanks for the hard work on this.

    Regards,
    Victor

  • I expected when I was reading about the deep linking stuff in this and your previous posts for the structure to be as follows:

    _navigationService.Navigate(“MasterDetailPage/X/Y”);

    Where:
    MasterDetailPage is essentially an empty page with a blank/default master page
    X – is whatever navigation menu you wish to have when clicking the hamburger menu
    Y – is whatever main page you wish to have displayed in the main application

    However, on inspection in the Sandbox projects it turns out that X never makes it into the menu, and the Sandbox only displays the default also in this situation (I proved this by commenting out the buttons in the default) which confirmed that either my understanding of how to use the deep linking is flawed (seems pretty likely) or there is some issue with master detail page linking in the style outlined above. Any clarification would be appreciated!

    • Your understanding of deep linking is flawed 🙂 When using a MasterDetailPage, you must have your menu defined within the Master property of the page. Think of it as you do not navigate to a navigation menu. So X would be the detail, and Y would be the next page and so on.

  • Will Prism support other platforms of Xamarin like Xamarin.Mac, Apple Watch, Android Wear, TVOS, Android TV, etc in future?

Follow Me

Follow me on Twitter, subscribe to my YouTube channel, and watch me stream live on Twitch.