internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.DependencyResolver.GetService <ISuspensionDriver>();

            _viewModelChanged.Subscribe(vm => {
                var page  = default(IViewFor);
                var frame = Window.Current.Content as Frame;

                if (frame == null)
                {
                    frame = new Frame();
                    Window.Current.Content = frame;
                }

                page = Window.Current.Content as IViewFor;
                if (page == null)
                {
                    page          = RxApp.DependencyResolver.GetService <IViewFor>("InitialPage");
                    frame.Content = (UIElement)page;
                }

                page.ViewModel = vm;
                Window.Current.Activate();
            });

            SuspensionHost.ShouldInvalidateState
            .SelectMany(_ => driver.InvalidateState())
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
            .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
            .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
            .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
            .SelectMany(x => driver.LoadState <IApplicationRootState>())
            .LoggedCatch(this,
                         Observable.Defer(() => Observable.Return(RxApp.DependencyResolver.GetService <IApplicationRootState>())),
                         "Failed to restore app state from storage, creating from scratch")
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.DependencyResolver.GetService <IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            _viewModelChanged.Subscribe(vm => {
                var page = default(IViewFor);
                var frame = Window.Current.Content as Frame;

                if (frame == null) {
                    page = RxApp.GetService<IViewFor>("InitialPage");

                    frame = new Frame() {
                        Content = page,
                    };

                    Window.Current.Content = frame;
                }

                page.ViewModel = vm;
                Window.Current.Activate();
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => {
                    ViewModel = x;
                });

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            _viewModelChanged.StartWith(ViewModel).Where(x => x != null).Subscribe(vm => {
                var page = default(IViewFor);
                var frame = RootVisual as PhoneApplicationFrame;

                page = RxApp.GetService<IViewFor>("InitialPage");
                if (frame == null) {
                    frame = new PhoneApplicationFrame() {
                        Content = page,
                    };
                }

                page.ViewModel = vm;
                var pg = page as PhoneApplicationPage;
                if (pg != null) {
                    pg.BackKeyPress += (o, e) => {
                        if (ViewModel.Router.NavigationStack.Count <= 1 ||
                            ViewModel.Router.NavigateBack.CanExecute(null)) {
                            return;
                        }

                        e.Cancel = true;
                        ViewModel.Router.NavigateBack.Execute(null);
                    };
                }

                RootVisual = frame;
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => {
                    ViewModel = x;
                });

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            var window = new UIWindow(UIScreen.MainScreen.Bounds);
            _viewModelChanged.Subscribe(vm => {
                var frame = RxApp.GetService<UIViewController>("InitialPage");
                var viewFor = frame as IViewFor;
                if (viewFor != null) {
                    viewFor.ViewModel = vm;
                }

                window.RootViewController = frame;
                window.MakeKeyAndVisible();
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }