是否可以在 Windows Phone 7 中预加载程序集? [英] Is it possible to preload an assembly in Windows Phone 7?

查看:19
本文介绍了是否可以在 Windows Phone 7 中预加载程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app in which I have a lot of references and the load time was not acceptable to me. I have removed the splash screen image and created an animated loading screen by having a separate project with no reference to the main application which then navigates to the first page of the rest of the app. It does start up fast now but it's a little lacking still.

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

I would like to do another animation right before the load screen goes away. The only way I can think of to do this is to actually preload the assemblies needed for the navigation to the next page, do an animation, and then navigate.

我试过了

  • OnNavigatedFrom 但动画没有时间运行,因为从那时起页面将很快被新页面替换.
  • OnNavigatingFrom 也没有帮助,因为它会在我调用 NavigationService.Navigate();
  • 后立即调用
  • 搜索网络和 Stack Overflow :)
  • 我还考虑通过让下一页显示加载屏幕的副本并在那里执行最后一个动画来伪造它,但它无法匹配加载屏幕动画的当前状态并且更难维护
  • OnNavigatedFrom but the animation doesn't have time to run since the page will be replaced by the new page very quickly from that point.
  • OnNavigatingFrom is no help either as it is called as soon as I call NavigationService.Navigate();
  • Searching the web and Stack Overflow :)
  • I also considered faking it a bit by having the next page show a duplicate of the load screen and do the last animation there, but it can't match the current state of the load screen animation and is harder to maintain

感谢您的任何想法!

推荐答案

事实证明,您只需创建要导航到的页面的新实例即可预加载.不幸的是,这必须在 UI 线程上完成,这可能会导致动画变慢,至少在我的经验中是这样.

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();
    }


}

这篇关于是否可以在 Windows Phone 7 中预加载程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆