1

我有一个应用程序,其中有很多参考资料,加载时间对我来说是不可接受的。我已经删除了初始屏幕图像并创建了一个动画加载屏幕,方法是创建一个不引用主应用程序的单独项目,然后导航到应用程序其余部分的第一页。它现在确实启动很快,但仍然有点缺乏。

我想在加载屏幕消失之前做另一个动画。我能想到的唯一方法是实际预加载导航到下一页所需的程序集,制作动画,然后导航。

我努力了

  • OnNavigatedFrom但是动画没有时间运行,因为从那时起页面将很快被新页面替换。
  • OnNavigatingFrom也无济于事,因为我一打电话就打电话NavigationService.Navigate();
  • 搜索网络和堆栈溢出 :)
  • 我还考虑通过让下一页显示加载屏幕的副本并在那里做最后一个动画来伪装它,但它无法匹配加载屏幕动画的当前状态并且更难维护

感谢您的任何想法!

4

2 回答 2

0

如果要强制加载程序集,只需从该程序集中引用一个类型。

例如,类似Console.WriteLine(typeof(YourAssembly.SomeType));的东西会强制加载YourAssembly.

现在对于您的问题,也许您可​​以使用用户控件?将主页的内容放在用户控件中。显示加载页面,在后台创建用户控件,让动画播放,然后当动画播放完毕后,将页面内容替换为用户控件。

于 2012-04-25T13:21:04.277 回答
0

It turns out that you can preload by just creating a new instance of the page you are going to navigate to. Unfortunately that has to be done on the UI thread which can cause animation slowdown, at least in my experience.

Here is a sample of how to do an animation, then preload, then do another animation before navigating. :

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-28T22:42:26.027 回答