0

アプリケーションまたはアクティベーションを開始した後、BackgroundAudioPlayerが再生されているかどうかを確認し、再生している場合はプレーヤーのページに移動します。NavigationService を使用できないことはわかっていますが、App.xaml.cs では、Activated のように RootVisual を使用する必要があることがわかりましたが、機能していません。RootVisual が null です。最初のものにはエラーはありませんが、問題は 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 には何も書き込まないでください (ナビゲーション コンテキストに関して)。次の 2 つの手順に従います。

STEP-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 に答える