事實證明,您可以通過創建您要導航到的頁面的新實例來預加載。不幸的是,至少在我的經驗中,必須在可能導致動畫放緩的UI線程上完成。
下面是如何執行動畫,然後預加載,然後在導航之前執行另一個動畫的示例。 :
public partial class LoadScreen : PhoneApplicationPage
{
public LoadScreen()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
var sb = new Storyboard();
// create your animation here
sb.Completed += (sender, args) => PreLoad();
sb.Begin();
}
private void PreLoad()
{
// this is the part that actually takes time and causes things to get loaded
// you may need it in a try/catch block depending on what is in your constructor
var page = new PageToNavigateTo();
// now create an animation at the end of which we navigate away
var sbOut = new Storyboard();
// create your animation here
sbOut.Completed += (sender, args) => NavigateToNextScreen();
sbOut.Begin();
}
private void NavigateToNextScreen()
{
// navigate here
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
// remove the loading screen from the backstack so the user doesn't see it again when hitting the back button
NavigationService.RemoveBackEntry();
}
}
我在這裏測試了你的想法,但看起來程序集是在啓動時加載的,而不是僅在執行該行時。用戶控制的想法是一個很好的想法,但不符合我想要做的。雖然謝謝! – 2012-04-26 18:23:50