[英]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.