在 Windows Phone 中导航回来时刷新页面
我有两个页面可供浏览和浏览。一个称为 MainPage,它是一个数据透视页面,另一个是称为 AddNewHistoryPage 的普通页面/类。 MainPage 中有一个名为 DisplayHistory 的函数,我想在从 AddNewHistoryPage 导航回 MainPage 时调用该函数。
我发现有一个受保护的函数,名为 OnNavigedTo。有人可以帮助找到更多信息,例如
- 如果我想在主页中调用 DisplayHistory ,则应将 OnNavieratedTo 函数编写在 MainPage 中,
- “base.OnNavigedTo(e)”是什么意思?
I have two pages that I navigate to and from. One is called the MainPage which is a Pivot page and the other is an ordinary page/class called the AddNewHistoryPage. There is a function called DisplayHistory in the MainPage that I would like to call on navigation back to MainPage from the AddNewHistoryPage.
I found that there is a protected function called OnNavigatedTo. Could someone help to find a little more information, such as
- The OnNavigatedTo function should be written in the MainPage if I want to call the DisplayHistory in the mainPage
- what does ' base.OnNavigatedTo(e)' mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
导航到“显示历史记录”页面时,您应该保存手机状态,这样当导航回主页时,您需要保留的信息将继续保留。
此外,当使用将在 MainPage 上使用的 OnNavigedTo 函数时,您必须编写一条语句来检查它是从哪些页面导航的......例如 DisplayHistory。
如果您不使用或不编写该语句,则每次访问该页面时都会运行该函数。
WP7 深度导航
上面的链接在学习逻辑删除和必须将特定内容保存到内存 ICE 时(在紧急情况下)对我帮助很大。
希望这会对您有所帮助! :)
You should save your phones state when navigating to the DisplayHistory page, so when navigating back to main page your information you need retained will stay retained.
Also when using the function OnNavigatedTo that would be used on MainPage but you would have to write a statement checking which pages it was navigated from....such as DisplayHistory.
If you don't use or that write that statement, every time the page is accessed it will run that Function.
WP7 Navigation in Depth
This Above link helped me a lot when learning tombstoning and having to save specific things to memory ICE(In Case of Emergency).
Hope this will help you out! :)
Keeano Martin 的链接应该足以回答您的第一个问题。
关于你的第二个问题:
'base.OnNavigateTo(e)' 调用基类 OnNavigateTo 方法。
您的页面继承自基类:“PhoneApplicationPage”。如果您不重写 OnNavigedTo 方法,则将直接调用基类实现。当您重写方法时,您通常应该调用基类实现(使用您发布的代码)。如果您不这样做,那么基类实现中的任何代码都将永远不会运行,并且您可能会得到一些意外的行为。
Keeano Martin's Link should be enough to anwser your first question.
Regarding your second question:
'base.OnNavigatedTo(e)' calls the base classes OnNavigateTo method.
Your page inherits from a base class: 'PhoneApplicationPage'. If you do not override the OnNavigatedTo method then the base classes implementation will be called directly. When you do override a method then you should [usually] call the base class implementation (using the code you posted). If you don't do this then any code in the base classes implementation will never be run and you will probably get some unexpected behaviour.