这里与此主题有点相关: Async XML Reading in Windows Phone 7
我正在开发一个Windows Phone应用程序,我的Search.xaml.cs文件中有一个搜索功能。通过单击按钮调用它,它会创建一个搜索查询并使用它调用DownloadStringInBackground
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已存储为
public static string[] finalResult;
感谢您寻找:)
答案 0 :(得分:3)
这里有关于在页面之间传递值的演练。
答案 1 :(得分:0)
如果你没有使回调函数静态,你可以这样做:
Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Result.xaml", UriKind.Relative)));
如果回调函数必须是静态的,您可以使用:
Deployment.Current.Dispatcher.BeginInvoke();