![](/img/trans.png)
[英]How to seperate textBox1 type action and use textBox1.Text to get string from internet?
[英]get text from textbox1 and set it on textblock1 in other form
我想從form1上的textbox1獲取輸入並將其設置在form2的textblock1上,但文本不會顯示
form1代碼:
private void Button_Click_3(object sender, RoutedEventArgs e)
{
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(textbox1.Text + ".txt");
var line = await FileIO.ReadLinesAsync(file);
if (textbox1.Text == line[0] && tb2.Password == line[1])
{
textbox1.Text = line[0];
Frame.Navigate(typeof(form2));
}
}
public string MyValue
{
get { return textbox1.Text; }
}
Form2上的代碼
var logged = new MainPage();
textblock1.Text = logged.MyValue;
有什么幫助嗎? 感謝:D
試試form1
Frame.Navigate(typeof(form2), textbox1.Text);
窗口2
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string name = e.Parameter as string;
if (!string.IsNullOrWhiteSpace(name))
{
textblock1.Text = name ;
}
else
{
textblock1.Text = "Name is required. Go back and enter a name.";
}
}
該鏈接可能有幫助
您無法在form2
獲得所需的值,因為您正在創建MainPage
的新實例,該實例當然不包含剛從中導航的實例的值。
您將需要將該值作為參數傳遞給form2
。 為此,您可以使用不同的Navigate
重載,該重載帶有一個附加參數:
private void Button_Click_3(object sender, RoutedEventArgs e)
{
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(textbox1.Text + ".txt");
var line = await FileIO.ReadLinesAsync(file);
if (textbox1.Text == line[0] && tb2.Password == line[1])
{
textbox1.Text = line[0];
Frame.Navigate(typeof(form2), textbox1.Text);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.