私は問題はWindow.Current.Content
がFrame
であり、あなたがApp.xaml.cs
コードからそれを見ることができるよう、通常我々は、rootFrame
としてこれを呼び出すMVVM光によって、あなたはWindow.Current.Content = null;
を設定したということだと思う:
Frame rootFrame = Window.Current.Content as Frame;
たら、あなたは、ヌルとして設定し、次にページをホストするために使用されFrame
がなくなって、あなたは、まずそれがApp.xaml.cs
に同じようFrame
の新しいインスタンスを作成する必要があります。
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
「AppShellを設定するセットアップコード」のコードを投稿していないので、コードで考えられる問題を推測して答えを書いています。ページをリセットするためのデモがここにあります:
Window.Current.Content = null;
var rootFrame = new Frame();
Window.Current.Content = rootFrame;
await Task.Delay(1000);
_navigationService.NavigateTo(ViewModelLocator.SecondPageKey, "lala");
まだ問題がある場合は、コメントを残すか、私たちにもっとコードを教えてください。
ありがとうございました。私は私の質問で言ったように、ウィンドウコンテンツをテストとしてヌルに設定していました...実際にクリアされたことを証明するだけです。私はフレームに設定する必要があることを理解しています。あなたのコードは役に立ちますが、_navigationServiceの詳細をいくつか教えてください。 – Scott
これは 'private readonly INavigationService _navigationService;'で、MVVM Lightテンプレートを使用してUWPアプリケーションを作成すると、 'MainViewModel.cs'で見つけることができます。これのインスタンスは実際には 'ViewModelLocator.cs'で作成されます。 –