Skip to content

Instantly share code, notes, and snippets.

@edsnider
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsnider/10035854 to your computer and use it in GitHub Desktop.
Save edsnider/10035854 to your computer and use it in GitHub Desktop.
Clearing WP back stack in MvvmCross
namespace MyApp.Portable.ViewModels
{
public class BaseViewModel : MvxViewModel
{
protected void ShowViewModelAndClearBackStack<TViewModel>()
where TViewModel : BaseViewModel
{
ShowViewModel<TViewModel>();
ChangePresentation(new ClearNavBackStackHint());
}
}
}
namespace MyApp.Portable.PresentationHints
{
public class ClearNavBackStackHint : MvxPresentationHint
{ }
}
namespace MyApp.WP8.Views.ViewPresenters
{
public class CustomWP8ViewPresenter : MvxPhoneViewPresenter
{
public CustomWP8ViewPresenter (PhoneApplicationFrame rootFrame) : base(rootFrame)
{ }
public override void ChangePresentation(MvxPresentationHint hint)
{
if (hint is ClearNavBackStackHint)
{
while (RootFrame.BackStack.Any())
{
RootFrame.RemoveBackEntry();
}
}
base.ChangePresentation(hint);
}
}
}
namespace MyApp.WP8
{
public class Setup : MvxPhoneSetup
{
public Setup(PhoneApplicationFrame rootFrame) : base(rootFrame)
{
}
protected override IMvxPhoneViewPresenter CreateViewPresenter(PhoneApplicationFrame rootFrame)
{
var presenter = new CustomWP8ViewPresenter(rootFrame);
Mvx.RegisterSingleton(presenter);
return presenter;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment