【问题标题】:Messed up BackStage with Universal App (Windows Phone 8.1)使用通用应用程序 (Windows Phone 8.1) 搞砸了后台
【发布时间】:2015-02-18 03:05:50
【问题描述】:

我在我创建的通用应用程序的 windows phone 8.1 部分中遇到了导航问题。我会尽力解释。

我有以下内容(对不起,我的间距/制表符似乎在下面搞砸了!)

1) 主页(单击应用栏上的 + 并导航到 2) ->> 2) 新项目页面(点击图片预览,导航到 3) ->> 3)捕获页面(点击按钮) ->> 从凸轮按钮(未实现) ->> 从照片按钮 ->> 4) 从相册中选择或拍照 [- -----点击接受并返回新项目(2)和 将照片显示为预览。

但是当我点击返回键时,从技术上讲,它应该让我返回 到我的主页(1),但它执行以下操作:

   First back press: Goes back to Capture Page (3)
   Second back press: Goes back to New Item Page (2)
   Third back press: Goes back to Home (1)

我正在使用 WP 文件选择器来选择照片,但我是否选择 一个或按返回键,它会转到位于我的 OnActivated 事件 我的 App.xaml.cs

在选择一个 photo 或按返回键,它会检查 args.Files.Count 是否有 是否返回照片,我已将以下代码行添加到 看看它是否会有所作为:

if (((Frame)Window.Current.Content).BackStackDepth > 2) ((Frame)Window.Current.Content).BackStack.Remove(((Frame) Window.Current.Content).BackStack[2]); if (((Frame)Window.Current.Content).BackStackDepth > 1) ((Frame)Window.Current.Content).BackStack.Remove(((Frame) Window.Current.Content).BackStack[1]);

但这并没有什么不同。如果我按后退键 而不是选择一张照片,我的BackStageDepth 是 2 并且它 包含主页 (1) 和新项目页面 (2)。如果我选择一张照片, 它包含这 2 个,还包含 Capture Page (3)。

但这是我不明白的奇怪行为。假设我按背面 键并没有选择照片。我的 BackStageDepth 是 2 并且只包含 主页(1)和新项目页面(2)所以当我得到这些行时 如上所述,它会跳过 > 2 的那个并删除新项目 第2页)。当我检查它已被删除并且我的BackStageDepth 已降至 1。

这不是我想要达到的目标,但我试图了解什么是 继续。无论如何,当我继续运行代码时,我得到了我的新项目页面 (2) 显示并且我的预览图像仍然是空的,因为我按下了返回键 在 WP 文件选择器上。

现在奇怪的是,当我再次按下返回键时,我放了一个 HardwareButtons_BackPressed 的断点位于 NavigationHelper 但如果我检查(框架) Window.Current.Content).BackStackDepth,它现在告诉我它 2 而不是1。如果我检查它,(Frame)Window.Current.Content).BackStack[0] 仍然是我的主页 (1) 但 (Frame)Window.Current.Content).BackStack[1] 现在设置为我检查时未列出的捕获页面 (3) 在方法WPPickedFile.

这是为什么呢?我完全糊涂了,但我不知道自己做错了什么,但这显然与我在启动 WP File Picker 时离开应用程序的事实有关,就好像我没有离开主页一样(1) 到 捕获页面 (3) 无需单击按钮即可启动 WP 文件选择器, 导航按预期工作。

任何建议将不胜感激

谢谢。

PS:很抱歉格式不好,但我无法修复它!

【问题讨论】:

    标签: c#-4.0 windows-phone windows-phone-8.1 win-universal-app


    【解决方案1】:

    我的 backstack 实际上并没有搞砸。我发现 windows phone 8.1 可以有多个框架的困难方式,我完全

    关于在调用 FilePicker 的页面之前导航回上一页,我终于找到了一种方法,它看起来很干净并且不会调用导航,因此不会调用返回堆栈的页面

    #if WINDOWS_PHONE_APP
        protected async override void OnActivated(IActivatedEventArgs e)
        {
            base.OnActivated(e);
    
            continuationManager = new ContinuationManager();
    
            Frame rootFrame = CreateRootFrame();
            await RestoreStatusAsync(e.PreviousExecutionState);
    
            if (rootFrame.Content == null)
            {
                rootFrame.Navigate(typeof(LocationsPage));
            }
    
            var continuationEventArgs = e as IContinuationActivatedEventArgs;
            if (continuationEventArgs != null)
            {
                if (rootFrame.Content is CaptureTypePage)
                {
                    if (rootFrame.CanGoBack)
                        rootFrame.GoBack();
                }
                // Call ContinuationManager to handle continuation activation
                continuationManager.Continue(continuationEventArgs, rootFrame);
            }
    
            Window.Current.Activate();
        }
    
    #endif
    

    重要的部分是:

    if (rootFrame.Content is CaptureTypePage)
    {
      if (rootFrame.CanGoBack)
        rootFrame.GoBack();
    }
    

    continuationManager.Continue(continuationEventArgs, rootFrame);

    通过调用GoBack,它会移除CaptureTypePage并将rootFrame的CurrentSourcePageType设置为预览窗口所在的'New Item Page'。

    然后我在“新项目页面”上实现了接口IFileOpenPickerContinuable,这由 continuationManager.Continue 函数调用,即

    case ActivationKind.PickSaveFileContinuation:
      var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable;
      if (fileSavePickerPage != null)
      {
        fileSavePickerPage.ContinueFileSavePicker(args as 
        FileSavePickerContinuationEventArgs);
      }
      break;
    

    我希望这对其他人有所帮助,并且不会像我一样浪费时间!如果您有更简洁的方法,请添加到此帖子。我很想知道。

    谢谢。

    【讨论】:

      猜你喜欢
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多