0
我有在App.Xaml.cs具有下面的代碼的問題:Window.Current.Content設定一個框架,但其他的頁面不導航
var gamePage = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (gamePage == null)
{
// Create a main GamePage
gamePage = new Frame();
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the GamePage in the current Window
Window.Current.Content = gamePage;
gamePage.Navigate(typeof(MainMenu));
}
// Ensure the current window is active
Window.Current.Activate();
這對於一個應用程序相當標準初始化。這也是同微軟如何概括你應該這樣做:但是
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx
,當我再次在框架調用(在這種情況下,在OnNavigateTo,因爲現在我要確保我可以切換左右頁,這將在稍後移動)它不做任何事,並坐在同一頁面上。換句話說如下:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var gamePage = Window.Current.Content as Frame;
gamePage.Navigate(typeof(GamePage));
}
但是,我不能調用this.Frame像微軟建議我可能或可能不是問題。
因此,回顧一下,問題在於我無法使用加載到Window.Current.Content中的標準Frame對象從一個頁面導航到另一個頁面。我可以驗證應用程序是否進入OnNavigateTo並且第一頁開關可以正常工作。但是,當我嘗試再次切換頁面時,它不再工作。
任何想法?任何幫助是極大的讚賞!