3

I have a WinRT "Windows Store" app with two pages: a list page and an edit page. When the user clicks a list item and selects "Edit" from the bottom app bar, I pass the item to the edit page. What I need from there is to support two possible user actions:

  • If the user navigates back using the Back Button (top navigation), I want the unmodified item to be returned the calling page.

  • If the user clicks on a supplied "Save" button (on the edit page), I want to update the various properties of the item, save it to a data store and automatically return the modified item to the calling page.

Either way, the calling page needs to update its display with the changes made to the item, if any. I can do most of this, but I can't figure out how to return the item to the calling page. How do I go about this?

Please keep in mind, there will be other pages added to the app going forward (which will also be called from the main "lists" page). I need to make an accommodation such that when I return from a given "child" page back to the lists page, the behavior of the list page will differ based on which page is being returned from. (Hope that makes sense...).

Bonus question: I'd also like to capture the back navigation event to notify the user that the modified item will not be saved and give them the option to continue, save and continue or cancel the return navigation action. Is that possible?

TIA

4

2 回答 2

1

我认为这种方法对于我要解决的问题是错误的。我从来没有找到一种特别好的方法来将子页面的值返回到父页面。

相反,我的问题允许采用不同的方法。我有一个我在应用程序中跟踪的项目的主列表<>。这个 List<> 被序列化到本地存储。当我调用子页面时,我传入现有项目(用于编辑)或空实例(用于添加)。

当我到达子页面时,我在 LoadState 方法中拉出传入的项目。如果传入的项目为空,我创建一个新实例,它成为我的工作实例。

从那里,我允许用户根据需要编辑项目。当用户保存项目时,我从存储中反序列化主 List<>。然后,我要么将新项目添加到主 List<>,要么替换 List<> 中的现有项目。然后我将主 List<> 重新序列化到存储中,替换已经存在的内容。

当用户返回调用(父)页面时,我从 LoadState 方法的存储中重新获取主 List<> 项目并重新填充页面。如果更新了现有项目或添加了新项目,则父页面会准确反映更改。这就是我最终需要发生的一切。

我不知道是否有办法做我最初要求的事情,但至少在这种情况下,我决定我不需要这样做。这种替代方法或类似方法可能是在“返回”事件上将对象传递到导航堆栈中的父页面的唯一方法。

于 2012-12-06T22:18:51.750 回答
0

我相信,如果我理解您的问题,那么您正在寻找以下方面的东西:

WinJS.Navigation.navigate("/path/to/your/page.html", {/*this object will be the second 'options' parameter to your page's ready function });

. . .

// This function is called whenever a user navigates to this page. It populates the page elements with the app's data.
ready: function (element, options) {
于 2012-12-02T13:56:10.807 回答