Windows phone 8.1 Windows Phone、Prism.StoreApps:如何避免在暂停或终止后激活特定页面?
我确实希望确保,如果某个应用程序被导航到某个页面,则该应用程序在挂起或终止后的上一个页面上位于另一个页面上。就我而言,这个页面是用来拍照的。我不希望用户在应用程序处于后台后返回此页面,因为它没有上下文信息。上下文信息在previuos页面上 我如何使用Prism.StoreApps实现这一点Windows phone 8.1 Windows Phone、Prism.StoreApps:如何避免在暂停或终止后激活特定页面?,windows-phone-8.1,prism-storeapps,Windows Phone 8.1,Prism Storeapps,我确实希望确保,如果某个应用程序被导航到某个页面,则该应用程序在挂起或终止后的上一个页面上位于另一个页面上。就我而言,这个页面是用来拍照的。我不希望用户在应用程序处于后台后返回此页面,因为它没有上下文信息。上下文信息在previuos页面上 我如何使用Prism.StoreApps实现这一点 背景:如果应用程序刚刚挂起,则应用程序的状态在恢复后保持不变,因此最后一个活动页面再次处于活动状态。在这种情况下,我真的不知道如何设置另一个页面处于活动状态。如果应用程序被终止,Prim.StoreApps
背景:如果应用程序刚刚挂起,则应用程序的状态在恢复后保持不变,因此最后一个活动页面再次处于活动状态。在这种情况下,我真的不知道如何设置另一个页面处于活动状态。如果应用程序被终止,Prim.StoreApps将恢复导航状态并导航到最后一个活动视图模型,从而导航到最后一个活动页面。在这种情况下,我也不知道如何更改导航状态,以便导航到另一个页面。与此同时,我自己也喜欢一个工作解决方案。可能不是最好的,也可能有更好的解决方案,但它是有效的 对于恢复应用程序,我将处理恢复事件: 对于终止后的页面还原,我首先使用App类中的一个属性:
private void OnResuming(object sender, object o)
{
// Check if the current root frame contains the page we do not want to
// be activated after a resume
var rootFrame = Window.Current.Content as Frame;
if (rootFrame != null && rootFrame.CurrentSourcePageType == typeof (NotToBeResumedOnPage))
{
// In case the page we don't want to be activated after a resume would be activated:
// Go back to the previous page (or optionally to another page)
this.NavigationService.GoBack();
}
}
public bool MustPreventNavigationToPageNotToBeResumedOn { get; set; }
public App()
{
this.InitializeComponent();
// We assume that the app was restored from termination and therefore we must prevent navigation
// to the page that should not be navigated to after suspension and termination.
// In OnLaunchApplicationAsync MustPreventNavigationToPageNotToBeResumedOn is set to false since
// OnLaunchApplicationAsync is not invoked when the app was restored from termination.
this.MustPreventNavigationToPageNotToBeResumedOn = true;
this.Resuming += this.OnResuming;
}
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
// If the application is launched normally we do not prevent navigation to the
// page that should not be navigated to.
this.MustPreventNavigationToPageNotToBeResumedOn = false;
this.NavigationService.Navigate("Main", null);
return Task.FromResult<object>(null);
}
public override void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode,
Dictionary<string, object> viewModelState)
{
if (((App)Application.Current).MustPreventNavigationToPageNotToBeResumedOn)
{
// If must prevent navigation to this page (that should not be navigated to after
// suspension and termination) we reset the marker and just go back.
((App)Application.Current).MustPreventNavigationToPageNotToBeResumedOn = false;
this.navigationService.GoBack();
}
else
{
base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
}
}