【发布时间】:2018-11-20 02:04:34
【问题描述】:
在我班级的一个方法中,我调用Login.Show(),它是一个Login Window。我希望窗口在单击登录按钮时将电子邮件传递回类,而不创建类的新实例。
有什么办法吗?
目前我有
Login loginWindow;
public void AppStartup {
loginWindow = new Login();
loginWindow.Show();
//in this instance I'd like the email to be returned here
Login.xaml.cs内
public void Login_Click(object sender, RoutedEventArgs e)
{
string email;
try {
email = InputEmail.Text;
//ideally I would like to return email to AppStartup without
//using new AppStartup(); , rather back in the same instance
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
【问题讨论】:
-
我会阅读
mvvm和binding的 wpf -
只需在 LoginWindow 类中添加一个公共属性并在 Login_Click 处理程序中设置它
-
您知道,在 WPF(甚至 WinForms)应用程序中使用
Console.WriteLine(ex.Message);方法很棘手? -
您可能希望使用
ShowDialog()而不是Show()。然后就可以在调用后访问成员变量@JonSuggest。
标签: c# wpf return-value