发送文本到另一个页面 [英] Sending text to another Page

查看:71
本文介绍了发送文本到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个对MainPage.xaml计算一些数字的应用程序.我还有另一个页面称为history.xaml,我希望MainPage.xaml中的这些数字可以自动转到history.xaml.

Hi,

I created application that calculates some numbers to MainPage.xaml. I have another page called history.xaml and i want those numbers from MainPage.xaml to go automatically to history.xaml.

历史记录页面上现在有文本框,无法在其中写入文本,并将其保存到本地数据库.

There is now textbox on history page and im able to write there text and it will save it to localdatabase.

示例.我手动在此处写了"1000",然后单击添加",它将显示在文本框上方.当您从MainPage.xaml获得一个数字时,我希望它自动显示在文本框中.我什至不需要那个文本框或添加按钮 它会自动在那里.

example. I wrote there '1000' manually and after i click 'add' it will show up above the textbox. I want it to automatically to show up over the textbox when you get a number from MainPage.xaml. I dont even need that textbox or add button if i could get it automatically there.


推荐答案

页面之间的所有内容不会自动发生.您告诉该应用随身携带一些数据,或者在发生此"情况时转到另一页.您可以检查是否击中了TextBox1的Keypress_Down事件,以及是否是文本长度 TextBox1中的3个字符,请移至其他页面.

Anything between pages doesn't happen automatically. You tell the app to carry some data with it or go to the other page when 'this' happens. Like you can check that if Keypress_Down event of TextBox1 is hit and if so is the length of text in TextBox1 is 3 characters, move to other page.

主要有三种方法,尽管最后一种有点复杂,我将在这里解释两种非常基本的方法,

There are mainly three ways though the last one is a bit complicated I'll explain two very basic here,

要在这些页面之间切换,您将使用如下代码,

To move between these pages you'll be using code like this,

string url ="/History.xaml";
NavigationService.Navigate(new Uri(url,UriKind.Relative));

string url = "/History.xaml";
NavigationService.Navigate(new Uri(url, UriKind.Relative));

如果您想随身携带MainPage.xaml的TextBox1中的文本,这就是您要做的

If you want to carry with you the text in let's say TextBox1 of MainPage.xaml, this is what you'll do

string url = string.Format("/History.xaml?MyText = {0}",TextBox1.Text);
NavigationService.Navigate(new Uri(url,UriKind.Relative));

string url = string.Format("/History.xaml?MyText={0}",TextBox1.Text);
NavigationService.Navigate(new Uri(url, UriKind.Relative));

现在在历史记录"页面上,将查询字符串参数"MyText"中的数据可供您检索和处理(在其他文本框中输入)

Now on History page the data in the query string parameter "MyText" is available for you to retrieve and process (put in other text box say)

      受保护的重写void OnNavigatedTo(NavigationEventArgs e)
       {
          试试
           {
                             TextBox2.Text = NavigationContext.QueryString [" MyText"];
           }
       }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                TextBox2.Text = NavigationContext.QueryString["MyText"];
            }
        }

请注意,您应该期待改进错误检查.

Note that you should look forward to improve error checking.


这篇关于发送文本到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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