Somewhat related to this topic here: Async XML Reading in Windows Phone 7
I'm developing a Windows Phone app, and I have a search function in my Search.xaml.cs file. It is called by clicking 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 has been 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 doing it in the callback, but I get a nullobject exception due to the static keyword. How can I ensure that finalResult has been populated, and that I can navigate to Result.xaml and reference the data in finalResult on that page. Alternately, how can I pass Words or finalResult to Result.xaml?
Thanks for looking :)