在这里与此主题有些相关:Windows Phone 7中的异步XML读数7

我正在开发Windows Phone应用程序,并且我的search.xaml.cs文件中有一个搜索功能。通过单击按钮来调用它,它会创建搜索查询并使用它调用下载stringinbackground

    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;
    }

Final Result已被存储为

public static string[] finalResult;

感谢您的查看:)

有帮助吗?

解决方案

这里有一项在页面之间传递值的演练。

如何:在Windows Phone上执行页面导航

其他提示

如果您不使回调函数静态,则可以执行此操作:

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

如果回调函数必须是静态的,则可以使用:

Deployment.Current.Dispatcher.BeginInvoke();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top