Search code examples
windowsstackmvvmcrossback

MvvmCross remove back stack windows app


How can I clear the back stack in windows apps (not windows phone)?
I am using MvvmCross v3. Where is the most correct place to put it?

I have read this post http://edsnider.net/2014/04/07/clearing-windows-phone-nav-back-stack-in-mvvmcross/ where he is using CustomWP8ViewPresenter

    public override void ChangePresentation(MvxPresentationHint hint)
    {
        if (hint is ClearNavBackStackHint)
        {
            while (RootFrame.BackStack.Any())
            {
                RootFrame.RemoveBackEntry();
            }
        }

        base.ChangePresentation(hint);
    }

My problem is that in windows app I do not have RootFrame.RemoveBackEntry() as an option.

Any ideas?


Solution

  • Your IMvxWindowsFrame mentioned in comments is just simple wrapper around Windows.UI.Xaml.Controls.Frame instance. You can get this wrapped instance by calling:

    _rootFrame = (Frame) rootFrame.UnderlyingControl;
    

    Then you can delete your backstack like this:

    if (hint is ClearNavBackStackHint)
    {
        if (_rootFrame.BackStackDepth > 0)
        {
            _rootFrame.BackStack.RemoveAt(_rootFrame.BackStack.Count - 1);
        }
    }