使用通用应用程序搞砸了BackStage(Windows Phone 8.1)

时间:2015-02-18 03:05:50

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

我的Windows Phone 8.1中的导航问题我创建的通用应用程序的一部分。我试着解释一下。

我有以下内容(抱歉,我的间距/标签似乎在下面搞砸了!)

1) Home Page (click on a + on the app bar and it navigates to 2)
  ->> 2) New Item Page (click on the image preview and it navigates to 3)
    ->> 3) Capture Page (tap on a button)
      ->> From Cam button (not implemented)
       ->> From Photo button
          ->> 4) Select from album or Take a photo
         [- -----Tap Accept and it goes back to New Item (2) and 
                 display the photo as a preview.

But when I click on the back key, it should technically bring me back to my Home Page(1) but instead it does the following:

   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)

I'm using the WP File Picker to select a photo, but whether I select one or press the back key, it goes to my OnActivated event located in my App.xaml.cs

In the async Method (WPPickedFile) which is called when selecting a photo or pressing the back key, it checks if args.Files.Count has returned a photo or not and I've added the following lines of code to see if it would make a difference:

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)。如果我选择一张照片, 它包含这两个,它还包含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] 现在设置为Capture Page(3),当我检查它时,它没有被列出 方法WPPickedFile

为什么?我完全糊涂了,但我无法弄清楚我做错了什么,但这显然与我在WP文件选择器时离开应用程序的事实有关。推出好像我不是从主页(1)转到 捕获页面(3)而不单击按钮以启动WP文件选择器, 导航按预期工作。

任何建议都将不胜感激

感谢。

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

1 个答案:

答案 0 :(得分:0)

我的背包实际上并没有搞砸。我发现Windows Phone 8.1可能有多个框架的困难方式,我完全

关于在调用FilePicker之前导航回上一页的问题,我终于找到了一种方法,它看起来很干净,并没有调用nagivation,因此页面是靠背

#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设置为“新项目页面”。预览窗口在哪里。

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

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

我希望这可以帮助别人,并且不会像我那样浪费时间!如果你有更简洁的方法,请添加到这篇文章。我很想知道。

感谢。