WPF框架源码问题
我创建了一个内部有框架的 WPF 应用程序。我可以将一些其他页面附加到此框架,例如
frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);
问题是加载此页面(Page1.xaml)后加载同一框架中的另一个页面(Page2.xaml) Page1.xaml 是自动处理的还是仍在后台运行?我找不到框架源页面的处置方法。谁能解释一下吗?
I've created a WPF application with a frame inside. I can attach some other pages to this frame like
frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);
The question is after loading this page (Page1.xaml) an Load another page in the same frame (Page2.xaml)
is the Page1.xaml disposed automaticly or is it still running in background? I could not find a dispose method for a frame source page. Can anyone explain this please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Frame
旨在提供导航内容的能力;正如您所做的那样,打包导航内容的首选方法是Page
。具体来说,可以使用 Navigate 方法来导航 Frame,并且将维护导航历史记录的生命周期,其中“history”是此处的关键字。在导航历史记录中,框架不会维护导航过的每个页面的实例,以避免过多的内存消耗。因此,使用导航控件时不会记住状态,并且每次导航到页面时都会创建一个新实例。
换句话说,当您离开框架中的页面时,该对象就会被释放。
MSDN 上有一篇关于使用框架的好文章。
Frame
is designed to provide the ability for navigating content; the preferred way to package content for navigation is aPage
as you are doing. Specifically, the Frame can be navigated with the Navigate methods and will maintain the lifetime of navigation history, where "history" is the keyword here.Within the history of the navigation, the Frame will not maintain an instance of each Page navigated to avoid excessive memory consumption. Consequently, the state is not remembered when using the Navigation controls and a new instance is created each time the page is navigated to.
In other words, when you navigate away from a page in a frame, the object is disposed.
MSDN has a good read on using Frames.