WPF框架源码问题

发布于 2024-08-27 12:43:21 字数 228 浏览 2 评论 0原文

我创建了一个内部有框架的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ记忆︶ㄣ 2024-09-03 12:43:21

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 a Page 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文