更改窗口内容时的资源管理 [英] Resource management when changing window content

查看:28
本文介绍了更改窗口内容时的资源管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我对如何在一个窗口的多个页面"之间导航没有完全了解.

First of all, I do not feel completely educated on how to navigate between multiple "pages" of a window.

例如,我有一个名为 MainWindow 的窗口.在这里面,我有一个页眉和一个页脚.中间是一个包含内容的面板.该面板最初将包含内容 A.单击 A 中的某些内容后,我想从视图中删除 A 并显示一个包含内容 B 的新面板.但是,我希望 B 显示在同一窗口中(即,不隐藏窗口和打开一个新的).隐藏/显示这些面板是正确的方法吗?

For example, I have a Window called MainWindow. Inside of this, I have a header and a footer. In the middle is a panel which contains content. This panel will originally contain content A. Upon clicking something in A, I want to remove A from view and show a new panel with content B. However, I want B to be shown in the same window (i.e., not hide the window and open a new one). Is hiding/showing these panels the correct way to go about it?

如果使用面板切换机制是正确的方式,那么我担心资源管理.如果我将面板 A 设置为不可见,而将面板 B 设置为可见,我是否仍会加载来自两个面板的资源?如果我有大量面板要在它们之间切换,我不想为所有面板加载内容,而是要加载活动面板.我将如何确保正确处理这些不同视图之间的资源和内存?

If using the panel switching mechanism is the correct way, then I am worried about resource management. If I set panel A to not be visible, and panel B to be visible, will I still have resources from both panels loaded? If I have a large number of panels to switch between, I would not want to load content for all of them, but rather the active one. How would I go about making sure that I am correctly handling resources and memory between these different views?

如果我对如何在单个窗口内切换视图有完全错误的想法,请告诉我.谢谢.

If I have the completely wrong idea about how to switch views within a single window, please let me know. Thanks.

推荐答案

另一种选择是只使用一个 ContentPresenter,并将您的个人面板"放入其中,但一次只能放置一个.

One alternative is to just use a single ContentPresenter, and put your individual "panels" in there, but only one at a time.

您可以使用数据绑定来更改 ContentPresenter 中的绑定内容,而不是翻转可见性.这一次只会留下一个视图",从而防止需要加载大量"面板.

Instead of flipping visibility, you could use Data Binding to change the bound content within the ContentPresenter. This would only leave a single "view" in place at a time, preventing the neeed for "a large number" of panels to be loaded.

这篇关于更改窗口内容时的资源管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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