This is an extremely complex problem, and there is no simple solution here. There is no magic API that would just work for any app to solve this problem.
The core problem with passing navigation data is Tombstoning. The only piece of data that is tombstoned by default is the Navigation URI. so if you're using a QueryString parameter, it'll get picked up automatically by tombstoning and your code. Any time you'll manually pass a instance of an object though, you'll have to manually do tombstoning for that instance yourself.
So, if you navigate to "/CowDetails.xaml?ID=1" your page will probably have perfect tombstoning just by picking up on the ID Querystring Parameter. However, if you somehow provide CowDetails page with a "new Cow() { ID = 1}" you'll have to make sure to tombstone and zombificate this value yourself.
Also, there's the issue of timing. While calling NavigationService.Navigate, the page you're navigating too doesn't have an actual instance yet. So even though you're navigating to FooPage and have the FooData ready, there's no way to immediately connect FooPage to FooData. You'll have to wait until the PhoneApplicationFrame.Navigated event has fired in order to provide FooPage with FooData.
The way I normally deal with this is problem:
- Have a BasePage with an Object type Data property
- Have a NavigationHelper get the page URI and Data: NavigationHelper.Navigate("foo.xaml", fooData)
- Have NavigationHelper register to PhoneApplicationFrame.Navigated event and if it's "foo.xaml" set the BasePage.Data to FooData.
- Have BasePage use JSON.Net to tombstone and zombificate BasePage.Data.
- On BasePage, I've got a OnDataSet virtual method that is invoked once the Data property is populated either by Zombification or Navigation. In this method, everything that has to do with business data happens.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…