如何从一个xaml页面导航到另一个页面并传递值? [英] How do I navigate from one xaml page to another, and pass values?

查看:169
本文介绍了如何从一个xaml页面导航到另一个页面并传递值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此主题相关的一些信息: Windows Phone 7中的异步XML读取

Somewhat related to this topic here: Async XML Reading in Windows Phone 7

我正在开发Windows Phone应用程序,并且Search.xaml.cs文件中具有搜索功能.通过单击一个按钮可以调用它,它会创建一个搜索查询并使用它来调用DownloadStringInBackground

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已存储为

finalResult has been stored as

public static string[] finalResult;

在搜索类中.我的问题是,我可以在哪里放置导航命令(NavigationService.Navigate(new Uri("/Result.xaml",UriKind.Relative));)?我尝试在回调中执行此操作,但是由于static关键字,我得到了nullobject异常.如何确保已填充finalResult,并且可以导航到Result.xaml并引用该页面上的finalResult中的数据.或者,如何将Word或finalResult传递给Result.xaml?

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?

感谢您的关注:)

推荐答案

这里有一个在页面之间传递值的演练.

There is a walkthrough here on passing values between pages.

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

这篇关于如何从一个xaml页面导航到另一个页面并传递值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆