将视图预加载到 WPF 应用程序的 UI 中。怎么可能呢?

发布于 2024-11-25 08:08:50 字数 263 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唠甜嗑 2024-12-02 08:08:50

到目前为止,我还不需要这样做,但是:

您可以尝试将所需的内容加载到由于布局决定而不会显示的控件中。这应该强制创建内容,即使它不会立即显示。

当您想要“引入内容”时,请将其从可视化树中的当前位置删除(确切的方法可能取决于其父级的确切位置),然后将其作为另一个可见控件的子级重新插入。

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.

北城孤痞 2024-12-02 08:08:50

考虑实现一个简单的翻转内容控件。
它只应该提供两个依赖属性,其中包含两个内容模板和一个依赖属性 (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 triggering SwitchTemplate property set second ContentTempale as main of a Flip Control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文