如何在应用程序启动预加载XAML? [英] How to preload XAML at app startup?

查看:112
本文介绍了如何在应用程序启动预加载XAML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这不是在主屏幕上显示出相当大的用户控件,但用户几乎总是使用它以后。这需要一些时间来加载首次(分析BAML等)然后其他实例的构造非常快。 ?现在的问题是如何使其启动画面时在应用程序启动预载

I have pretty large UserControl that's not showed at main screen, but user almost always uses it later. It takes some time to load for the first time (parse BAML etc.) then other instances are constructed pretty fast. The question is how to make it to preload at app startup during splash screen?

我的想法是在启动构建usused例如:

My idea was to construct usused instance at startup:

void Startup()
{
    //....
    new MyCustomControl();
    //....
} 



但后来我不得不处理特殊情况下,建设(它的不具有无参数的默认构造函数)。我觉得应该有更方便的方法。

but then I have to deal with special case construction (it's does not have default constructor with no args). I think there should be more convenient way.

推荐答案

要预加载复杂的用户界面,让他们花费更少的时间时,他们实际上是看在屏幕上,我们将不得不遵循以下步骤...

To preload complex UIs so that they take less time when they are actually "viewed" on the screen, we would have to follow following steps...


  1. 请它隐形模式下加载。改变你的绑定能见度触发为主。这样,UI线程将既不块,也不需要时间来执行隐形模式渲染

  1. Make it load in Invisible mode. Change all you bindings to visibility trigger based. This way UI thread would neither block nor take time to perform the rendering in invisible mode.

<Style TargetType="TextBlock">
        <Style.Triggers>
                <Trigger Property="IsVisible" Value="True">
                        <Setter Property="Text" Value="{Binding Value}"/>
                </Trigger>
        </Style.Triggers>
</Style>


  • 分离从UI加载的数据上下文(视图模型)加载。这意味着由用户控制表示的任何数据可被装载在工作线程,然后在UI必须用Dispatcher.BeginInvoke通知()。确保这种情况发生时,用户界面是可见的,否则绑定将采取应有的作用步骤1。

  • Separate the data context (viewmodel) loading from the UI loading. What this means is any data represented by the user control can be loaded on worker thread and then the UI must be notified using Dispatcher.BeginInvoke(). Make sure that this happens when UI is visible otherwise the bindings would take effect due to step 1.

    在用户界面实际上是看,编排加载UI的地区...例如中使用扩展器,默认情况下崩溃他们......但用户界面查看时,开始使用滑动动画和内容的不透明度动画显示里面等等...

    When the UI is actually "viewed", choreograph the loading of UI's regions ... e.g. Use Expanders and collapse them by default... but when the UI is viewed, start sliding the expander using sliding animation and content opacity animation to show the contents inside it etc...

    在我们的应用中采用这种技术来实现复杂的用户界面加载快速响应。一个这样的UI这是观察不仅会阻塞UI线程,也需要20秒加载时,地理地图。使用上面的步骤负载减少到4秒,没有阻塞UI线程的途中发生。

    IN our application we employed such techniques to achieve complex UIs to load fast and be responsive. One such UI which was a geographical map when viewed would not only block the UI thread but also take 20 seconds to load. Using above steps the loading was reduced to 4 seconds and no blocking ocurred of the UI thread.

    我希望这些步骤将帮助你。

    I hope these steps will help you too.

    这篇关于如何在应用程序启动预加载XAML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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