Skip to content

Instantly share code, notes, and snippets.

@edsnider edsnider/BaseViewModel.cs
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.