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

查看:24
本文介绍了如何从一个 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 中的数据.或者,如何将 Words 或 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天全站免登陆