Smart Navigation is a Windows Phone navigation framework which allows you to pass complex data structures between pages in strongly typed and refactoring friendly manner and also automagically retrieving valid state after tombstoning.

Features
  • MVVM ready
  • Complex data structures transfer between pages
  • Fully strongly-typed, no strings or enums
  • Flexible page lifecycle monitoring
  • No magic “base” classes or interfaces
  • Tombstoning handling

Example project
https://smartnavigation.codeplex.com/releases/view/105136

Nuget




Setup

You need to provide a real NavigationFrame insinde InitializePhoneApplication() method.
Just add a single line of code: SmartNavigationService.Current.InitFrame(RootFrame);

private void InitializePhoneApplication()
{
    if (phoneApplicationInitialized)
        return;

    RootFrame = new PhoneApplicationFrame();
    //SmartNavigationInit
    SmartNavigationService.Current.InitFrame(RootFrame);
    RootFrame.Navigated += CompleteInitializePhoneApplication;

    // Handle navigation failures
    RootFrame.NavigationFailed += RootFrame_NavigationFailed;

    // Ensure we don't initialize again
    phoneApplicationInitialized = true;
}

How to use

You call Navigate
  • specifying your ViewModel type via generic argument
  • first parameter is uri to your page.xaml
  • second parameter is lambda expression which will call the method on your ViewModel passing parameters after navigation completes

SmartNavigationService.Current.Navigate<SecondPageDataContext>("/Views/SecondPage.xaml", context => context.EntryPoint(UserData));

SmartNavigationService will automaticly assing DataContext property for an newly opened page and
will call method which you specified with proper arguments.

Your EntryPoint method can contain any number of arguments of any types which is serialized properly by Json.Net.Also EntryPoint can contain NavigationEventArgs argument.

If your EntryPoint contains NavigationEventArgs than you don’t need to pass any value to it when navigating, just leave it null.
context => context.EntryPoint(UserData, null)


public class SecondPageDataContext : INotifyPropertyChanged
{
    //Setup attributes to be notified about navigation in your View Model
    [OnNavigatedTo]
    public void OnNavigatedTo(NavigationEventArgs e) { }

    [OnNavigatingFrom]
    public void OnNavigatingFrom(NavigatingCancelEventArgs e) { }

    //Invoked when navigating first time to the page which uses "this" as DataContext,
    //or after tombstoning.
    public void EntryPoint(UserData userData)
    {
        UserData = userData;
    }

    private UserData _userData;
    public UserData UserData
    {
        get { return _userData; }
        set
        {
            _userData = value;
            OnPropertyChanged("UserData");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}


This project is using Json.Net library for serializing\deserializing data.
Copyright (c) 2007 James Newton-King
https://json.codeplex.com/license

Last edited Apr 15, 2013 at 8:47 PM by EBCEu4, version 39