Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了一个 WPF 应用程序,里面有一个框架。我可以在这个框架上附加一些其他页面,比如
frame1.Source = new Uri("Page1.xaml", UriKind.RelativeOrAbsolute);
问题是在加载此页面 (Page1.xaml) 之后在同一框架中加载另一个页面 (Page2.xaml) 是自动处理 Page1.xaml 还是仍在后台运行?我找不到框架源页面的处置方法。谁能解释一下。
Frame旨在提供导航内容的能力;为导航打包内容的首选方法是Page您正在做的事情。具体来说,Frame 可以使用 Navigate 方法进行导航,并将保持导航历史的生命周期,其中“历史”是这里的关键字。
Frame
Page
在导航历史中,Frame不会维护每个导航的 Page 的实例,以避免过多的内存消耗。因此,在使用导航控件时不会记住该状态,并且每次导航到页面时都会创建一个新实例。
换句话说,当您离开框架中的页面时,该对象被释放。
MSDN 对使用 Frames 有很好的阅读。