How to go from one xaml page to another and pass values?

This is partly due to this topic: Reading Async XML in Windows Phone 7

I am developing a Windows Phone application and I have a search function in the Search.xaml.cs file. It is called by pressing a button, it creates a search query and calls DownloadStringInBackground with it

private void SearchQuery(object sender, EventArgs e) { string temp = "http://api.search.live.net/xml.aspx?Appid=myappid&query=randomqueryhere&sources=web"; DownloadStringInBackground(temp); } public static void DownloadStringInBackground(string address) { WebClient client = new WebClient(); Uri uri = new Uri(address); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCallback); client.DownloadStringAsync(uri); } private static void DownloadStringCallback(Object sender, DownloadStringCompletedEventArgs e) { // Fancy manipulation logic here finalResult = words; } 

finalResult is stored as

 public static string[] finalResult; 

in the search class. My question is: where can I put the Navigate command (NavigationService.Navigate (new Uri ("/Result.xaml", UriKind.Relative));)? I tried to do this in a callback, but I got a nullobject exception due to a static keyword. How can I guarantee that finalResult has been populated and that I can go to Result.xaml and reference the data in finalResult on this page. Alternatively, how can I pass words or finalResult to Result.xaml?

Thanks for watching :)

0
search windows-phone windows-phone-7 navigation
Dec 14 '10 at 10:18
source share
2 answers
+3
Dec 14 '10 at 10:34
source share

If you do not put a static callback function, you can do this:

 Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Result.xaml", UriKind.Relative))); 

If the callback function should be static, you can use:

 Deployment.Current.Dispatcher.BeginInvoke(); 
0
Dec 14 '10 at 10:39
source share



All Articles