简体   繁体   English

将TextBox文本传递给导航页面

[英]Passing TextBox Text to Navigated Page

I am trying to pass data from a textbox in one page to a text block in the navigated page. 我试图将数据从一个页面中的文本框传递到导航页面中的文本块。 I have some code but I am finding an error when running it here is my coding. 我有一些代码,但我在运行它时发现错误是我的编码。

From the page I want to send the data from: 从我想要发送数据的页面:

 private void button1_Click(object sender, RoutedEventArgs e)
        {if (txtSID.Text != null)
            {
                string StudentID = txtSID.Text;


                var url = string.Format("/BookingConf.xaml?StudentID={0}", StudentID);
                NavigationService.Navigate(new Uri(url, UriKind.Relative));
            }

Code from the Navigated Page: 导航页面中的代码:

   protected override void OnNavigatedTo(NavigatingEventArgs e)
    {
        String StudentID;

        if (NavigationContext.QueryString.TryGetValue
            ("studentID", out StudentID))
        {// load event data, and set data context
            ReferanceST.Text = StudentID;
        }
    }

The issue is that when I run the application I get an error on the 'OnNavigationTo(NavigationEventArgs e)' saying no suitable method found to override. 问题是,当我运行应用程序时,我在'OnNavigationTo(NavigationEventArgs e)'上收到错误,说没有找到合适的方法来覆盖。 In order to fulfil this i placed the 'if' statement but it made no difference. 为了实现这一点,我放置了'if'语句,但它没有任何区别。

Please help me resolve this issue. 请帮我解决这个问题。 Thank you. 谢谢。

The error is happening because you miss named the override method. 发生错误是因为您错过了命名覆盖方法。

The error is the smoking gun 错误是吸烟枪

"no suitable method found to override" “找不到合适的方法来覆盖”

To fix this 解决这个问题

 protected override void OnNavigationTo(NavigatingEventArgs e)
    {

should be 应该

 protected override void OnNavigatedTo(NavigatingEventArgs e)
    {

MSDN Reference MSDN参考

The OnNavigatingTo takes the NavigationEventArgs, not the NavigatingEventArgs. OnNavigatingTo采用NavigationEventArgs,而不是NavigatingEventArgs。

Change your line to: 将您的行更改为:

protected override void OnNavigatedTo(NavigationEventArgs e)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM