NEW FEATURE: View Participation in the Navigation Lifecycle

74 views
Skip to first unread message

Rishi Oberoi

unread,
Jan 29, 2011, 10:11:08 AM1/29/11
to nro...@googlegroups.com
I don't know how many guys are aware of an interface called ISupportNavigationLifecycle - well, its purpose is to provide "logical hooks" into the navigation process, the idea being that you can interact with the navigation process without getting into its specifics. In other words, it allows participation in the navigation process (normally from the ViewModel) whilst abstracting away the navigation infrastructure from the navigated-content. The contact for this interface is quite simple: 
    public interface ISupportNavigationLifecycle
    {
        string Title { get;  }

        void Initialize(ParametersCollection requestParameters);

        void Closing(Action<bool> confirmCallback);
    }
As you can tell, the contract provides for a title of the navigated content, helps receive the passed-in (and parsed) parameters, and provides an interception point to cancel a navigation request. Now, what's new is that I'm adding  a visual companion to the "logical hooks" - and it's defined by the ISupportNavigationViewLifecycle interface. It like the logical counterpart provides two hooks into the navigation process, one when initialized and one where closing, however because this is view-specific we don't abstract the navigation-specifics:
    public interface ISupportNavigationViewLifecycle
    {
        void Initialize(NavigationResponse response);

        void Closing(NavigationRequest request, Action closeCallback);
    }
Basically, what this allows you to do is to take certain view-based actions in response to being navigate-to or navigated-from. However, note this doesn't allow you to cancel the navigation - for that there is the ISupportNavigationLifecycle. And, a good use case for this interface is to execute animations when being navigate to or from, something like:
        public void Initialize(nRoute.Navigation.NavigationResponse response)
        {
            ((Storyboard)this.Resources["InitializeStoryboard"]).Begin();
        }

        public void Closing(nRoute.Navigation.NavigationRequest request, Action closeCallback)
        {
            var _storyboard = (Storyboard)this.Resources["CloseStoryboard"];
            _storyboard.Completed += (s, e) => closeCallback();
            _storyboard.Begin();
        }
Further, because we have the navigation info passed-in, we can alter the animation depending on the type of navigation mode - something WP7 does. So, in the big picture, this optional new feature should make the navigation process a lot more practicable for the View.

Rishi
Reply all
Reply to author
Forward
0 new messages