2016-05-31 49 views
1

我已經使用這篇文章添加BackButton到我的UWP應用程序:http://www.wintellect.com/devcenter/jprosise/handling-the-back-button-in-windows-10-uwp-apps然後我想添加ExtendedSplashScreen到我的應用程序。所以我用這篇文章:http://www.c-sharpcorner.com/UploadFile/020f8f/universal-windows-platform-and-extended-splash-screen/顯示擴展的splashscreen刪除我的後退按鈕C#UWP

但是,當我加入我的ExtendedSplashScreen後,BackButton從我在MainPage後打開的頁面消失。我知道它與我所稱的rootframe有關,但我無法弄清楚我應該改變什麼。任何幫助?

回答

2

這裏的問題是,在DismissExtendedSplash方法中,作者創建一個新的rootFrame並將其設置爲Window.Current.Content。這覆蓋App.xaml.cs中創建的rootFrame,因此處理後退按鈕的代碼將不起作用。要解決此問題,您可以使用Window.Current.Content as Frame中的DismissExtendedSplash方法獲得rootFrame,如下所示:

private async void DismissExtendedSplash() 
{ 
    await Task.Delay(TimeSpan.FromSeconds(3)); 
    // set your desired delay 
    //rootFrame = new Frame(); 
    //MainPage mainPage = new MainPage(); 
    //rootFrame.Content = mainPage; 
    //Window.Current.Content = rootFrame; 
    //rootFrame.Navigate(typeof(MainPage)); // call MainPage 
    ((Window.Current.Content) as Frame).Navigate(typeof(MainPage)); 
} 
1

來自DismissExtendedSplash方法的代碼覆蓋幀和OnNavigated事件。

你可以使用一個小技巧。在App.xaml.cs,使rootFrame一個全局變量:

public static Frame rootFrame; 

,並添加:

public static new App Current 
{ 
    get { return Application.Current as App; } 
} 

現在你DismissExtendedSplash可能是這樣的:

async void DismissExtendedSplash() 
{ 
    await Task.Delay(TimeSpan.FromSeconds(3)); // set your desired delay 
    App.rootFrame.Navigate(typeof(MainPage)); 
}