Creating a navigation cycle (and manage states)

Aug 23, 2012 at 7:42 AM

How i can create a navigation structure like windows phone. And handle the states. ie i am navigating from A -> B. Then terminating. so switching back to B. And press back button will navigate to A. Can you provide a sample that do the same.

Coordinator
Aug 24, 2012 at 9:46 AM

Hi,

No problem - this is one of the aims of the Okra App Framework to provide a solid MVVM navigation structure that correctly handles termination.

To start with I will assume that you are using the Okra INavigationManager to handle you app navigation -  see http://andyonwpf.blogspot.co.uk/2012/04/navigation-in-cocoon-mvvm-for-metro.html for more information. In addition the OkraShellSample in the Okra CodePlex downloads area, whilst designed to demonstrate something a custom shell, shows how to define your pages and navigation. You are probably best starting with the standard OkraBootstrapper (see http://andyonwpf.blogspot.co.uk/2012/05/getting-started-with-cocoon-navigation.html - note change of framework name!)

Once you have set up your application using the Okra navigation system you need to opt-in to handling termination. The full details are available at http://andyonwpf.blogspot.co.uk/2012/05/cocoon-navigation-making-your-app.html. In summary it is a single line that you need to add in the bootstrapper SetupNavigationManager() method,

public class AppBootstrapper : CocoonBootstrapper
{
    // *** Overriden base methods ***

    protected override void SetupNavigationManager()
    {
        NavigationManager.NavigationStorageType = NavigationStorageType.Local;
    }
}

This tells the Okra navigation system to store the navigation stack on suspension in local storage (you can also ask for this to be roaming) and upon application reactivation it will restore the stack. You can also do more advanced things - pass arguments to pages, store viewmodel specific state, etc. Check out my blog for further posts that might be of interest (http://andyonwpf.blogspot.co.uk/).

I have adding better samples and documentation on my current roadmap as I realise they are very useful to new users of the framework and will be coming in the future.

Regards,

    Andy

 

Sep 1, 2012 at 12:07 AM

Why is the SetupNavigationManager function now obsolete? Is this handled differently now?


Coordinator
Sep 2, 2012 at 11:24 AM

Hi jjbravo,

Don't worry - marking the SetupNavigationManager() method as obsolete (and removal in a future version) is just a cleaning up of the API surface. Instead you should simply place the code in the virtual SetupServices() method instead. The above example then becomes,

public class AppBootstrapper : CocoonBootstrapper
{
    // *** Overriden base methods ***

    protected override void SetupServices()
    {
        NavigationManager.NavigationStorageType = NavigationStorageType.Local;
    }
}

As background to this change, I originally added separate SetupServices() and SetupNavigationManager() methods so that certain services could potentially be lazy loaded in the future to improve startup performance. As the number of startup services have increased I've regretted making this architectural decision so thought I'd start the move over to a single simplified SetupServices() method.

Regards,

     Andy

Sep 3, 2012 at 4:52 AM

Thanks Andy.

Really like the framework so far.