简体   繁体   English

如何获取文本框文本从空白页到MainPage?

[英]How can I get textbox text from Blank Page to MainPage?

I want to get the text from blankpage.xaml to Mainpage.xaml 我想从blankpage.xaml到Mainpage.xaml的文本

I try to use this on MainPage.xaml: 我尝试在MainPage.xaml上使用它:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  enter.Text = (App.Current as App).trytext;
}

but there is an error that trytext could not found so i use and if statement: 但是有一个错误,找不到trytext,所以我使用if语句:

protected override void OnNavigatedTo(NavigationEventArgs e) 
{
        if (enter.Text == "")
        {
            enter.Text = "";
        }
        else
        {
            enter.Text = (App.Current as App).trytext;
        }
}

But when I get the text from blankpage there is no text when I get back to mainpage 但是当我从空白页获取文本时,回到首页时没有任何文本

please help! 请帮忙!

I'm not sure what you're trying to do, but it seems like you're trying to creating a variable that's accessible through the whole application? 我不确定您要做什么,但似乎您正在尝试创建一个可通过整个应用程序访问的变量?

If you want to pass some data from page 1 to page 2, you can pass the information in the Navigate method. 如果要将某些数据从第1页传递到第2页,则可以在Navigate方法中传递信息。

Probably you're calling something like 可能您正在拨打类似

Frame.Navigate(typeof(MainPage));

The Navigate method has an extra parameter in which you can pass your info. 导航方法有一个额外的参数,您可以在其中传递信息。 Call it like Frame.Navigate(typeof(MainPage), enter.Text); Frame.Navigate(typeof(MainPage), enter.Text);一样调用它

In the OnNavigatedTo you can get the value from the NavigationEventArgs. 在OnNavigatedTo中,您可以从NavigationEventArgs中获取值。 probably something like: 大概是这样的:

enter.Text = e.Parameter.ToString();

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

相关问题 如何将ListView从MainPage传递到其他xaml页面? - How can I pass a ListView from MainPage to other xaml page? 如何正确获取 MainPage? - How can correctly I get MainPage? C# WPF:如何从另一个页面访问页面控件以获取 textbox.text - C# WPF : how can i access page controls from another page to get textbox.text 如何从动态文本框中获取文本 - How can I get the text from the dynamic textbox 如何将那个page1.html paeg从mainpage.xaml带到secondpage.xaml并在webControl浏览器上显示? - how can i take that page1.html paeg from mainpage.xaml to secondpage.xaml and show on webControl browser? 如何从UserControl更改MainPage TextBlock文本? - How to change MainPage TextBlock text from UserControl? 如何从主页设置到UserControl内部的TextBox的绑定? - How to set Binding to TextBox that is inside of UserControl from mainpage? 如何从文本框而不是页面加载内容中获取当前编辑的文本 - how to get the currently edited text from textbox and not the page load contents 如何从 TextBox_KeyDown 事件中获取文本? WPF C# - How can I get the text from the TextBox_KeyDown event? WPF C# 如何使用Jquery或Javascript从Asp.Net TextBox控件获取文本? - How can I get the text from an Asp.Net TextBox control with Jquery or Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM