如题,我想在主窗口中实现多个“场景”的切换,所以想把每一个场景写在一个容器中来切换。
但是如果通过 Visable 来进行控制会有两个缺点,第一是不利于可视化设计
第二,所有的“场景”都被载入内存,造成不需要的资源浪费。
所以,有没有办法把容器写成独立的XAML,然后在代码中,控制哪一个容器作为 MainWindow 的Content。
就像是浏览器浏览网页一样,输入不同的网址显示不同的页面,只是这个页面是包含WPF控件的页面。
你好,
是不是可以考虑尝试使用TabContorl 来实现呢?大致思想是这样的: 每个tabitem 加载一种场景,然后在加载的时候只加载选定的tabitem, 即选定的场景。这种加载方式称为Lazy Loading。
请参考一下链接:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/be91e62b-d1ba-4448-a495-0720f35096cc
http://stackoverflow.com/questions/4276113/load-tabitem-content-when-it-is-selected-not-before-in-mvvm
http://stackoverflow.com/questions/4756657/lazy-loading-in-tabcontrols-mvvm
Lisa Zhu [MSFT] MSDN Community Support | Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.