WinForm应用程序中的WPF预编译资源?
我正在开发一个最初是 WinForm 的应用程序,但现在它使用带有 UI 的 WPF 窗口。交互工作一切正常,但首次显示 WPF 窗口时需要相当长的时间(大约 1-3 秒)才能显示。时间太长,以至于有些人怀疑应用程序是否崩溃了(直到内容显示)。第二次调用相同的窗口时,它们会很快出现。我需要他们第一次就快速出现。
我正在使用位于资源文件夹中的 XAML 样式和控件模板。然后,在 WPF 窗口的 XAML 中,我将它们合并到 Windows 资源字典中。这些(在 VS 2010 中)的构建操作需要设置为“资源”。 最好我想将它们保存在单独的文件中以便于维护。 据我了解,如果构建操作是“Page”,XAML 将被预编译并且加载速度应该更快,但如果我将其设置为 Page,我无法将它们合并到资源字典中。有办法解决这个问题吗?
我对 WPF 的这一部分相当陌生,到目前为止我的互联网搜索还没有成功。
需要明确的是:我并不是在谈论嵌入到 WinForms 中的 WPF 控件。我说的是从 WinForm 上下文中生成的完全独立的 WPF 窗口。
有没有办法预编译整个应用程序或至少预编译所有 XAML(都是静态的,没有动态 XAML)?
提前致谢!
编辑:用户界面无论如何都不重。这些有 5 到 20 个按钮和常用容器(基本上是带有 1 或 2 个堆叠面板的网格)。
更新: 我尝试使用“NGEN install appname”进行预编译 - 对 WPF 窗口加载没有影响。
我将所有资源和模板包含到 window.xaml 中 - 没有效果。 (window.xaml 是预编译的)
我在这里发现了一篇关于应用程序加载时预编译的非常有趣的文章:
http://www.codeproject.com/KB/dotnet/pre_JIT.aspx (我再次使用了“ittay ophir”建议的改进)
- :对 WPF 窗口加载没有影响...
加载时间在第一次加载时根本不会改变,但在所有连续加载时显着减少(20 毫秒或更短的加载) 。
这到底是怎么回事?
I am working on an application that started out as a WinForm but it is now utilizing WPF windows with UI. The interaction is all working beautifully but when the WPF windows are first shown it takes quite a long time (around 1-3 seconds) for them to show. So long that some wonder if the app has crashed (until the content shows). The second time the same windows are invoked they come up quickly. I need them to come up quickly the first time around.
I am making use of styles and control templates that are located as XAML in the resource folder. In the XAML for the WPF windows I then merge them into the windows resource dictionary. The Build Action for those (in VS 2010) needs to be set to "Resource".
Preferably I want to keep them in separate files for easy maintenance.
As far as I understand if the build action was "Page" the XAML would be precompiled and should load faster but if I set it to Page I cannot merge them into the resource dictionary. Is there a way around that?
I am fairly new to this part of WPF and so far my internet search hasn't been successful.
To be clear: I am not talking about WPF controls being embedded in WinForms. I am talking about entirely separate WPF windows that are spawned from the WinForm context.
Is there a way to precompile the entire app or at least all XAML (it's all static, no dynamic XAML)?
Thanks in advance!
Edit: The UIs are not heavy by any means. The ones in question have between 5 and 20 buttons and the usual containers (basically a grid with 1 or 2 stack panels).
Update:
I tried precompilation with "NGEN install appname" - no effect on WPF window load.
I included all resources and templates into the window.xaml - no effect.
(window.xaml is pre-compiled)
I found this really interesting article about pre-jitting upon app load here:
http://www.codeproject.com/KB/dotnet/pre_JIT.aspx
(I used the improvement suggested by 'ittay ophir')
- again: no effect on WPF window load...
The load times simply won't change on first load but they are significantly reduced on all consecutive loads (loads in 20ms or less).
What the heck is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何使用 XamlReader.LoadAsync 方法?
How about loading the XAML asynchronously using XamlReader.LoadAsync Method ?