前言
随着项目越来越复杂,我们可能会在App中添加很多逻辑,这些逻辑可能还要保证在窗口加载前执行,这样就导致在配置相对较差的电脑上,用户看到第一个界面的时间就会较长,体验不好,怎样解决呢。
我们可以添加一个启动页面,这个启动页在显示后先处理之前App中的逻辑,处理完后再加载原来的第一个页面,比如是登录页。
欢迎页
1 | <Window |
注意这里使用的是ContentRendered
事件,因为这个事件会在页面显示后触发。
代码
1 | private bool _isRun; |
注意
为了方式方法被触发多次,这里使用变量进行判断。
之前的App加载时的方法都放在了
DelayRun
中。
设置欢迎页为启动页
1 | <Application |