开发者

Resource management when changing window content

开发者 https://www.devze.com 2023-02-13 12:40 出处:网络
First of all, I do not feel completely educated on how to navigate between multiple \"pages\" of a window.

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

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?

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.


Instead of toggling visibility off and on, you should put a contentControl and switch it's contents to different UserControls.

That way there's no reference to the UserControl that's offscreen, and you can handle memory issues better.


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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号