private void Dialog_Loaded(object sender, RoutedEventArgs e) { this.AffirmativeButtonText = this.DialogSettings.AffirmativeButtonText; this.NegativeButtonText = this.DialogSettings.NegativeButtonText; switch (this.DialogSettings.ColorScheme) { case MetroDialogColorScheme.Accented: this.PART_NegativeButton.Style = this.FindResource("AccentedDialogHighlightedSquareButton") as Style; PART_PasswordBox.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_PasswordBox2.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_PasswordBox3.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBlock.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBox.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBox2.SetResourceReference(ForegroundProperty, "BlackColorBrush"); break; } }
internal Task <ChangePasswordDialogData> WaitForButtonPressAsync() { Dispatcher.BeginInvoke(new Action(() => { PART_PasswordBox.Focus(); })); TaskCompletionSource <ChangePasswordDialogData> tcs = new TaskCompletionSource <ChangePasswordDialogData>(); RoutedEventHandler negativeHandler = null; KeyEventHandler negativeKeyHandler = null; RoutedEventHandler affirmativeHandler = null; KeyEventHandler affirmativeKeyHandler = null; RoutedEventHandler auxHandler = null; KeyEventHandler auxKeyHandler = null; KeyEventHandler escapeKeyHandler = null; Action cleanUpHandlers = () => { PART_PasswordBox3.KeyDown -= affirmativeKeyHandler; this.KeyDown -= escapeKeyHandler; PART_NegativeButton.Click -= negativeHandler; PART_AffirmativeButton.Click -= affirmativeHandler; PART_AffirmativeButton.Click -= auxHandler; PART_NegativeButton.KeyDown -= negativeKeyHandler; PART_AffirmativeButton.KeyDown -= affirmativeKeyHandler; PART_AffirmativeButton.KeyDown -= auxKeyHandler; }; escapeKeyHandler = (sender, e) => { if (e.Key == Key.Escape) { cleanUpHandlers(); tcs.TrySetResult(null); } }; negativeKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(null); } }; affirmativeKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { if (EmailValidation()) { cleanUpHandlers(); tcs.TrySetResult(new ChangePasswordDialogData { CurrentPassword = PART_PasswordBox.Password, NewPassword = PART_PasswordBox2.Password, ValidatePassword = PART_PasswordBox3.Password, RecoveryEmail = PART_TextBox.Text, ValidateEmail = PART_TextBox2.Text }); } } }; auxKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(new ChangePasswordDialogData { RecoverPassword = true }); } }; negativeHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(null); e.Handled = true; }; affirmativeHandler = (sender, e) => { if (EmailValidation()) { cleanUpHandlers(); tcs.TrySetResult(new ChangePasswordDialogData { CurrentPassword = PART_PasswordBox.Password, NewPassword = PART_PasswordBox2.Password, ValidatePassword = PART_PasswordBox3.Password, RecoveryEmail = PART_TextBox.Text, ValidateEmail = PART_TextBox2.Text }); } e.Handled = true; }; auxHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new ChangePasswordDialogData { RecoverPassword = true }); e.Handled = true; }; PART_NegativeButton.KeyDown += negativeKeyHandler; PART_AffirmativeButton.KeyDown += affirmativeKeyHandler; PART_AuxiliaryButton.KeyDown += auxKeyHandler; PART_PasswordBox.KeyDown += affirmativeKeyHandler; PART_PasswordBox2.KeyDown += affirmativeKeyHandler; PART_PasswordBox3.KeyDown += affirmativeKeyHandler; PART_TextBox.KeyDown += affirmativeKeyHandler; PART_TextBox2.KeyDown += affirmativeKeyHandler; this.KeyDown += escapeKeyHandler; PART_NegativeButton.Click += negativeHandler; PART_AffirmativeButton.Click += affirmativeHandler; PART_AuxiliaryButton.Click += auxHandler; return(tcs.Task); }