[英]How do I navigate from one xaml page to another, and pass values?
與此主題相關的內容在這里: 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;
在搜索類中。 我的問題是,我可以在哪里放置導航命令(NavigationService.Navigate(new Uri(“ / Result.xaml”,UriKind.Relative));)? 我嘗試在回調中執行此操作,但是由於static關鍵字,我得到了nullobject異常。 如何確保已填充finalResult,並且可以導航到Result.xaml並引用該頁面上的finalResult中的數據。 或者,如何將Word或finalResult傳遞給Result.xaml?
感謝您的光臨:)
這里有一個在頁面之間傳遞值的演練。
如果不將回調函數設為靜態,則可以執行以下操作:
Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Result.xaml", UriKind.Relative)));
如果回調函數必須是靜態的,則可以使用:
Deployment.Current.Dispatcher.BeginInvoke();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.