|
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight;
using IssueVision.Common;
namespace IssueVision.Client
{
public partial class LoginForm : UserControl
{
#region "Constructor"
public LoginForm()
{
InitializeComponent();
if (!ViewModelBase.IsInDesignModeStatic)
{
// Use MEF To load the View Model
this.DataContext = App.Container.GetExportedValue<ViewModelBase>(
ViewModelTypes.LoginFormViewModel);
}
}
#endregion "Constructor"
#region "Event handlers"
private void userNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
// dynamically enable/disable error message
if (!string.IsNullOrWhiteSpace(this.loginScreenErrorMessageTextBox.Text))
this.loginScreenErrorMessageTextBox.Text = string.Empty;
// dynamically enable/disable login button
this.loginButton.IsEnabled = !(string.IsNullOrWhiteSpace(this.userNameTextBox.Text) ||
string.IsNullOrWhiteSpace(this.passwordPasswordBox.Password));
}
private void passwordPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
// dynamically enable/disable error message
if (!string.IsNullOrWhiteSpace(this.loginScreenErrorMessageTextBox.Text))
this.loginScreenErrorMessageTextBox.Text = string.Empty;
// dynamically enable/disable login button
this.loginButton.IsEnabled = !(string.IsNullOrWhiteSpace(this.userNameTextBox.Text) ||
string.IsNullOrWhiteSpace(this.passwordPasswordBox.Password));
}
private void securityAnswerPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
// dynamically enable/disable error message
if (!string.IsNullOrWhiteSpace(this.resetPasswordScreenErrorMessageTextBox.Text))
this.resetPasswordScreenErrorMessageTextBox.Text = string.Empty;
// dynamically enable/disable reset password button
this.resetPasswordButton.IsEnabled = !(string.IsNullOrWhiteSpace(this.newPasswordPasswordBox.Password) ||
string.IsNullOrWhiteSpace(this.confirmPasswordPasswordBox.Password) ||
string.IsNullOrEmpty(this.securityAnswerPasswordBox.Password));
}
private void newPasswordPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
// update the ActualPassword every time password changes
this.ActualPasswordTextBlock.Text = this.newPasswordPasswordBox.Password;
// dynamically enable/disable error message
if (!string.IsNullOrWhiteSpace(this.resetPasswordScreenErrorMessageTextBox.Text))
this.resetPasswordScreenErrorMessageTextBox.Text = string.Empty;
// dynamically enable/disable reset password button
this.resetPasswordButton.IsEnabled = !(string.IsNullOrWhiteSpace(this.newPasswordPasswordBox.Password) ||
string.IsNullOrWhiteSpace(this.confirmPasswordPasswordBox.Password) ||
string.IsNullOrEmpty(this.securityAnswerPasswordBox.Password));
}
private void newPasswordPasswordBox_LostFocus(object sender, RoutedEventArgs e)
{
// If confirm password is not empty, we need to re-validate confirm
// password after leaving password field
if (!string.IsNullOrEmpty(this.confirmPasswordPasswordBox.Password))
{
BindingExpression be = this.confirmPasswordPasswordBox.GetBindingExpression(PasswordBox.PasswordProperty);
if (be != null)
be.UpdateSource();
}
}
private void confirmPasswordPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
// dynamically enable/disable error message
if (!string.IsNullOrWhiteSpace(this.resetPasswordScreenErrorMessageTextBox.Text))
this.resetPasswordScreenErrorMessageTextBox.Text = string.Empty;
// dynamically enable/disable reset password button
this.resetPasswordButton.IsEnabled = !(string.IsNullOrWhiteSpace(this.newPasswordPasswordBox.Password) ||
string.IsNullOrWhiteSpace(this.confirmPasswordPasswordBox.Password) ||
string.IsNullOrEmpty(this.securityAnswerPasswordBox.Password));
}
#endregion "Event handlers"
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET