0

我想在启动应用程序或激活后检查 BackgroundAudioPlayer 是否正在播放,如果是,则转到带有播放器的页面。我知道我不能使用 NavigationService,并且我发现在 App.xaml.cs 中我应该像在 Activated 中一样使用 RootVisual,但它不起作用。RootVisual 为空。第一个没有错误,但问题是我到了 MainPage.xaml。那么我该如何解决呢?谢谢

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing)
            RootFrame.Navigate(new Uri("/PlayerPage.xaml", UriKind.RelativeOrAbsolute));
    }

    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing)
            (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/PlayerPage.xaml", UriKind.RelativeOrAbsolute));
    }
4

1 回答 1

1

我已经修改了你的代码,请看一下;它会为你工作。

从 Application_Activated 事件中删除您的代码并放入 Application_Launching 事件。并且不要在 Application_Activated 中写入任何内容。(就导航上下文而言)。遵循以下两个步骤:

步骤 1 转到WMAppManifest.xml文件并从默认任务中删除“ MainPage.xaml ”条目。并保持空条目NavigationPage。像这样NavigationPage=""

请参阅以下代码片段。

<Tasks>
    <DefaultTask  Name ="_default" NavigationPage=""/>
  </Tasks>
  <Tokens>
    <PrimaryToken TokenID="liveTilesToken" TaskName="_default">
      <TemplateType5>
        <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
        <Count>0</Count>
        <Title>liveTiles</Title>
      </TemplateType5>
    </PrimaryToken>
  </Tokens>

STEP-2相应地更新代码

private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Uri newUri = null;
            newUri = true ? new Uri("/MainPage.xaml", UriKind.Relative) : new Uri("/PlayerPage.xaml", UriKind.Relative);
            RootFrame.Navigate(newUri);
        }

希望能帮助到你。

谢谢你。

于 2013-10-16T09:24:41.753 回答