0

I'm working on a Windows Phone 7 Silverlight application. I was wondering if there is a case where the OnNavigatedTo() function is not called when using NavigationService.GoBack() ?

I'm working with two pages, one can add items to a database and the other can edit items in the database. The main page sends the user to each page with

    NavigationService.Navigate(new Uri(string.Format("/views/Add.xaml?parameter={0}", parameter), UriKind.Relative));
    NavigationService.Navigate(new Uri(string.Format("/views/Edit.xaml?parameter1={0}&parameter2={1}", param1, param2), UriKind.Relative));

Both options bring the user to a new page and both return the user via

    NavigationService.GoBack()

I have my OnNavigatedTo() function declared in MainPage, however only the Add page causes the function to execute while the Edit page seems to skip it on the return. The OnNavigatedTo() function repopulates an ObservableCollection to reflect the changes made by the user.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
bergermeister
  • 134
  • 2
  • 10

1 Answers1

0

No, the OnNavigatedTo() will definitely be called. You can verify that using breakpoints while debugging. I think the problem might be the way you update your Collection. Some more code might help.

naqvitalha
  • 793
  • 5
  • 9
  • my OnNavigatedTo() function looks like: `protectedOverride void OnNavigatedTo(System....) { ObservableCollection = controller.CollectAllItemsInDB(); }` – bergermeister Jul 18 '12 at 13:23
  • my controller looks like: `public ObservableCollection CollectAllItemsInDB() { var itemsInDB = from Item item in itemDB.Items select item; return new ObservableCollection(itemsInDB); } ` – bergermeister Jul 18 '12 at 13:24
  • Are you sure that you save the changes properly after editing? Insert a breakpoint before returning the ObservableCollection and see the data the query holds, verify if the changes were updated. – naqvitalha Jul 18 '12 at 17:42
  • The changes take place. If I back out of the app and launch it again I see the changes. It's only when returning from the edit page that I don't. I watch the OnNavigateTo function execute and return the items without the changes. Which makes me think it's my controller function for submitting the changes. I follow the same format as another section of code which works: `IQuerable itemQuery = from Item item in itemDB.Items where item.ItemId == newItem.ItemID select item; Item itemToUpdate = itemQuery.FirstOrDefault(); Make Changes to itemToUpdate; itemDB.SubmitChanges();` – bergermeister Jul 18 '12 at 19:32
  • ALso if you select an item that has been changed, the changes reflect in the edit page even though they do not show on the MainPage – bergermeister Jul 18 '12 at 19:39
  • Thanks for the help! I decided to just remove the item and insert the new one with updated information. Probably not the most efficient way but it'll work for now. – bergermeister Jul 20 '12 at 12:27