private void Login_Click(object sender, RoutedEventArgs e) { //获取用户输入的信息 string name = UserName.Text; string pwd = PassWord.Password; //调用代码 if (UserName.SelectedText == null) { MessageBox.Show("用户名或密码为空"); } else { UsersBll usersBll = new UsersBll(); UsersModel user = usersBll.GetByName(name); if (user == null) { MessageBox.Show("用户名错误"); } else { if (user.PassWord.Equals(Md5Helper.EncryptString(pwd))) { //将登陆者传递给主窗口 Application.Current.MainWindow.DataContext = user.DisplayName; Application.Current.MainWindow.Content = new ViewDataGrid(); } else { MessageBox.Show("密码错误"); } } } }