将视图预加载到 WPF 应用程序的 UI 中。怎么可能呢?
在 WPF 应用程序中,主窗口有一个可以加载用户控件之一的内容控件。这些用户控件中的每一个都有大约一千个小的、简单的自定义控件。这就是为什么切换到另一个用户控件的渲染时间令人不舒服。
我的问题是,以某种方式将视图预加载到 UI 中以便快速切换到另一个视图的正确方法是什么?是否可以以用户不可见的方式完成?或者渲染 XAML 应该始终在窗口的可见的、集中的部分中完成,因此无法预加载将来可能需要的内容?
请注意,我的意思并不是从数据库中预加载数据。
In a WPF application the main window has a content control to which one of user controls can be loaded. Each of these user controls has about a thousand small, simple custom controls. That's why the rendering time for swithing over to another user control is uncomfortable.
My question is, what would be the correct way of somehow preloading views into the UI so as swithing over to another view be fast? Can it be done in a way, not visible for a user? Or rendering a XAML should always be done in a visible, focused part of a window, so making it impossible to preload something that could be needed in the future?
Please, note, that I don't mean preloading data from a database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
到目前为止,我还不需要这样做,但是:
您可以尝试将所需的内容加载到由于布局决定而不会显示的控件中。这应该强制创建内容,即使它不会立即显示。
当您想要“引入内容”时,请将其从可视化树中的当前位置删除(确切的方法可能取决于其父级的确切位置),然后将其作为另一个可见控件的子级重新插入。
I haven't had need to do this so far, but:
You can try loading the content you want into a control which does not get displayed due to layout decisions. This should force the content to be created even though it will not be displayed immediately.
When you want to "bring the content in", remove it from the visual tree from its current position (the exact method might depend on what its parent is exactly) and re-insert it as a child of another, visible, control.
考虑实现一个简单的翻转内容控件。
它只应该提供两个依赖属性,其中包含两个内容模板和一个依赖属性 (
SwitchTemplate
),用于在提供的模板之间切换。因此,默认情况下,它将显示默认
ContentTemplate
,并通过触发SwitchTemplate
属性将第二个ContentTempale
设置为翻转控件的主要部分。Think about implementing a simple Flip Content Control.
It just should provide two Dependency Properties which holds two content templates and one Dependency Property (
SwitchTemplate
) to switch between provided templates.So by default it will show Default
ContentTemplate
, and by triggeringSwitchTemplate
property set secondContentTempale
as main of a Flip Control.