在我的类中的一个方法中,我调用了
目前,我的代码如下:
Login.Show()
,它是一个登录窗口
。当单击登录按钮时,我希望窗口能将电子邮件地址传回给该类,而不创建一个新的类实例。是否有任何方法可以实现这一点?目前,我的代码如下:
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)
。 - jazbConsole.WriteLine(ex.Message);
方法是有技巧的吗? - vasily.sibShowDialog()
而不是Show()
。这样,在调用之后,你就可以访问@Jon建议的成员变量了。 - Klaus Gütter