protected override void OnLoaded() { var settings = this.DialogSettings as LoginDialogSettings; if (settings != null && settings.EnablePasswordPreview) { var win8MetroPasswordStyle = this.FindResource("Win8MetroPasswordBox") as Style; if (win8MetroPasswordStyle != null) { PART_TextBox2.Style = win8MetroPasswordStyle; } } this.AffirmativeButtonText = this.DialogSettings.AffirmativeButtonText; this.NegativeButtonText = this.DialogSettings.NegativeButtonText; this.RegistrationButtonText = this.DialogSettings.RegistrationButtonText; switch (this.DialogSettings.ColorScheme) { case MetroDialogColorScheme.Accented: this.PART_NegativeButton.Style = this.FindResource("AccentedDialogHighlightedSquareButton") as Style; PART_TextBox.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBox2.SetResourceReference(ForegroundProperty, "BlackColorBrush"); break; } }
private void Dialog_Loaded(object sender, RoutedEventArgs e) { this.AffirmativeButtonText = this.DialogSettings.AffirmativeButtonText; this.NegativeButtonText = this.DialogSettings.NegativeButtonText; switch (this.DialogSettings.ColorScheme) { case TMPDialogColorScheme.Accented: this.PART_NegativeButton.Style = this.FindResource("AccentedDialogHighlightedButton") as Style; PART_TextBox.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBox2.SetResourceReference(ForegroundProperty, "BlackColorBrush"); break; } }
protected override void OnLoaded() { var settings = DialogSettings as SigninDialogSettings; if (settings != null && settings.EnablePasswordPreview) { var win8MetroPasswordStyle = FindResource("Win8MetroPasswordBox") as Style; if (win8MetroPasswordStyle != null) { PART_TextBox2.Style = win8MetroPasswordStyle; } } switch (DialogSettings.ColorScheme) { case MetroDialogColorScheme.Accented: PART_SignupButton.Style = FindResource("AccentedDialogHighlightedSquareButton") as Style; PART_TextBox.SetResourceReference(ForegroundProperty, "BlackColorBrush"); PART_TextBox2.SetResourceReference(ForegroundProperty, "BlackColorBrush"); break; } }
internal Task <LoginDialogData> WaitForButtonPressAsync() { Dispatcher.BeginInvoke(new Action(() => { this.Focus(); if (string.IsNullOrEmpty(PART_TextBox.Text)) { PART_TextBox.Focus(); } else { PART_TextBox2.Focus(); } })); TaskCompletionSource <LoginDialogData> tcs = new TaskCompletionSource <LoginDialogData>(); RoutedEventHandler negativeHandler = null; KeyEventHandler negativeKeyHandler = null; RoutedEventHandler affirmativeHandler = null; KeyEventHandler affirmativeKeyHandler = null; KeyEventHandler escapeKeyHandler = null; Action cleanUpHandlers = () => { PART_TextBox.KeyDown -= affirmativeKeyHandler; PART_TextBox2.KeyDown -= affirmativeKeyHandler; this.KeyDown -= escapeKeyHandler; PART_NegativeButton.Click -= negativeHandler; PART_AffirmativeButton.Click -= affirmativeHandler; PART_NegativeButton.KeyDown -= negativeKeyHandler; PART_AffirmativeButton.KeyDown -= affirmativeKeyHandler; }; 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) { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password }); } }; negativeHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(null); e.Handled = true; }; affirmativeHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password }); e.Handled = true; }; PART_NegativeButton.KeyDown += negativeKeyHandler; PART_AffirmativeButton.KeyDown += affirmativeKeyHandler; PART_TextBox.KeyDown += affirmativeKeyHandler; PART_TextBox2.KeyDown += affirmativeKeyHandler; this.KeyDown += escapeKeyHandler; PART_NegativeButton.Click += negativeHandler; PART_AffirmativeButton.Click += affirmativeHandler; return(tcs.Task); }
internal Task <LoginDialogData> WaitForButtonPressAsync() { Dispatcher.BeginInvoke(new Action(() => { this.Focus(); if (string.IsNullOrEmpty(PART_TextBox.Text) && !ShouldHideUsername) { PART_TextBox.Focus(); } else { PART_TextBox2.Focus(); } })); TaskCompletionSource <LoginDialogData> tcs = new TaskCompletionSource <LoginDialogData>(); RoutedEventHandler negativeHandler = null; KeyEventHandler negativeKeyHandler = null; RoutedEventHandler affirmativeHandler = null; KeyEventHandler affirmativeKeyHandler = null; RoutedEventHandler registrationHandler = null; KeyEventHandler registrationKeyHandler = null; KeyEventHandler escapeKeyHandler = null; Action cleanUpHandlers = null; var cancellationTokenRegistration = DialogSettings.CancellationToken.Register(() => { cleanUpHandlers(); tcs.TrySetResult(null); }); cleanUpHandlers = () => { PART_TextBox.KeyDown -= affirmativeKeyHandler; PART_TextBox2.KeyDown -= affirmativeKeyHandler; this.KeyDown -= escapeKeyHandler; PART_NegativeButton.Click -= negativeHandler; PART_AffirmativeButton.Click -= affirmativeHandler; RegistrationButton.Click -= registrationHandler; PART_NegativeButton.KeyDown -= negativeKeyHandler; PART_AffirmativeButton.KeyDown -= affirmativeKeyHandler; RegistrationButton.KeyDown -= registrationKeyHandler; cancellationTokenRegistration.Dispose(); }; escapeKeyHandler = (sender, e) => { if (e.Key == Key.Escape) { cleanUpHandlers(); tcs.TrySetResult(null); } }; negativeKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = null, ShouldRemember = RememberCheckBoxChecked }); } }; affirmativeKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = 1, ShouldRemember = RememberCheckBoxChecked }); } }; registrationKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = 2, ShouldRemember = RememberCheckBoxChecked }); } }; negativeHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = null, ShouldRemember = RememberCheckBoxChecked }); e.Handled = true; }; affirmativeHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = 1, ShouldRemember = RememberCheckBoxChecked }); e.Handled = true; }; registrationHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ButtonAction = 2, ShouldRemember = RememberCheckBoxChecked }); e.Handled = true; }; PART_NegativeButton.KeyDown += negativeKeyHandler; PART_AffirmativeButton.KeyDown += affirmativeKeyHandler; RegistrationButton.KeyDown += registrationKeyHandler; PART_TextBox.KeyDown += affirmativeKeyHandler; PART_TextBox2.KeyDown += affirmativeKeyHandler; this.KeyDown += escapeKeyHandler; PART_NegativeButton.Click += negativeHandler; PART_AffirmativeButton.Click += affirmativeHandler; RegistrationButton.Click += registrationHandler; return(tcs.Task); }
internal Task <SigninDialogData> WaitForButtonPressAsync() { Dispatcher.BeginInvoke(new Action(() => { Focus(); if (string.IsNullOrEmpty(PART_TextBox.Text)) { PART_TextBox.Focus(); } else { PART_TextBox2.Focus(); } })); TaskCompletionSource <SigninDialogData> tcs = new TaskCompletionSource <SigninDialogData>(); RoutedEventHandler signupHandler = null; KeyEventHandler signupKeyHandler = null; RoutedEventHandler signinHandler = null; KeyEventHandler signinKeyHandler = null; RoutedEventHandler cancelHandler = null; KeyEventHandler cancelKeyHandler = null; KeyEventHandler escapeKeyHandler = null; Action cleanUpHandlers = null; var cancellationTokenRegistration = DialogSettings.CancellationToken.Register(() => { cleanUpHandlers(); tcs.TrySetResult(null); }); cleanUpHandlers = () => { PART_TextBox.KeyDown -= signinKeyHandler; PART_TextBox2.KeyDown -= signinKeyHandler; this.KeyDown -= escapeKeyHandler; PART_SignupButton.Click -= signupHandler; PART_SigninButton.Click -= signinHandler; PART_CancelButton.Click -= cancelHandler; PART_SignupButton.KeyDown -= signupKeyHandler; PART_SigninButton.KeyDown -= signinKeyHandler; PART_CancelButton.KeyDown -= cancelKeyHandler; cancellationTokenRegistration.Dispose(); }; escapeKeyHandler = (sender, e) => { if (e.Key == Key.Escape) { cleanUpHandlers(); tcs.TrySetResult(null); } }; signupKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(new SigninDialogData { ShouldSignup = true }); } }; signupHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(new SigninDialogData { ShouldSignup = true }); e.Handled = true; }; signinKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { var isValid = IsUsernameValid(Username) && IsPasswordValid(Password); if (isValid) { cleanUpHandlers(); tcs.TrySetResult(new SigninDialogData { Username = Username, Password = PART_TextBox2.Password, ShouldSignup = false }); } } }; signinHandler = (sender, e) => { var isValid = IsUsernameValid(Username) && IsPasswordValid(Password); if (isValid) { cleanUpHandlers(); tcs.TrySetResult(new SigninDialogData { Username = Username, Password = PART_TextBox2.Password, ShouldSignup = false }); e.Handled = true; } }; cancelKeyHandler = (sender, e) => { if (e.Key == Key.Enter) { cleanUpHandlers(); tcs.TrySetResult(null); } }; cancelHandler = (sender, e) => { cleanUpHandlers(); tcs.TrySetResult(null); e.Handled = true; }; PART_SignupButton.KeyDown += signupKeyHandler; PART_SigninButton.KeyDown += signinKeyHandler; PART_CancelButton.KeyDown += cancelKeyHandler; PART_TextBox.KeyDown += signinKeyHandler; PART_TextBox2.KeyDown += signinKeyHandler; KeyDown += escapeKeyHandler; PART_SignupButton.Click += signupHandler; PART_SigninButton.Click += signinHandler; PART_CancelButton.Click += cancelHandler; return(tcs.Task); }