0

このトピックに多少関連しています: Windows Phone 7 での非同期 XML 読み取り

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;

検索クラスで。私の質問は、Navigate コマンド (NavigationService.Navigate(new Uri("/Result.xaml", UriKind.Relative));) をどこに置くことができるかということです。コールバックでやってみましたが、 static キーワードが原因で nullobject 例外が発生します。finalResult が設定されていること、および Result.xaml に移動してそのページの finalResult のデータを参照できることを確認するにはどうすればよいですか。または、Words または finalResult を Result.xaml に渡すにはどうすればよいですか?

見てくれてありがとう:)

4

2 に答える 2

3

ここには、ページ間で値を渡すためのウォークスルーがあります。

方法:WindowsPhoneでページナビゲーションを実行する

于 2010-12-14T10:34:54.267 に答える
0

コールバック関数を静的にしない場合は、次のようにすることができます。

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

コールバック関数を静的にする必要がある場合は、次を使用できます。

Deployment.Current.Dispatcher.BeginInvoke();
于 2010-12-14T10:39:05.247 に答える