From b04a162e57e0b610bef23271db31b35dcc21c3ed Mon Sep 17 00:00:00 2001 From: Vinicius Cunha Date: Thu, 31 Oct 2024 11:14:23 -0300 Subject: [PATCH 1/3] feat: Included setting "ChangeFocusOnUsernameFieldWithEnter" in LoginDialogSettings to change focus from the username field to the password field when pressing ENTER on the username field --- .../Controls/Dialogs/LoginDialog.cs | 41 ++++++++++++++----- .../Controls/Dialogs/LoginDialogSettings.cs | 2 + 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs index a44cd2d999..4a2d3e8a6a 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs @@ -224,6 +224,19 @@ public bool RememberCheckBoxChecked set => this.SetValue(RememberCheckBoxCheckedProperty, BooleanBoxes.Box(value)); } + /// Identifies the dependency property. + public static readonly DependencyProperty ChangeFocusWithEnterOnUsernameFieldProperty + = DependencyProperty.Register(nameof(ChangeFocusWithEnterOnUsernameField), + typeof(bool), + typeof(LoginDialog), + new PropertyMetadata(default(bool))); + + public bool ChangeFocusWithEnterOnUsernameField + { + get => (bool) this.GetValue(ChangeFocusWithEnterOnUsernameFieldProperty); + set => this.SetValue(ChangeFocusWithEnterOnUsernameFieldProperty, value); + } + #endregion DependencyProperties #region Constructor @@ -257,6 +270,7 @@ internal LoginDialog(MetroWindow? parentWindow, LoginDialogSettings? settings) this.SetCurrentValue(RememberCheckBoxVisibilityProperty, loginDialogSettings.RememberCheckBoxVisibility); this.SetCurrentValue(RememberCheckBoxTextProperty, loginDialogSettings.RememberCheckBoxText); this.SetCurrentValue(RememberCheckBoxCheckedProperty, loginDialogSettings.RememberCheckBoxChecked); + this.SetCurrentValue(ChangeFocusWithEnterOnUsernameFieldProperty, loginDialogSettings.ChangeFocusWithEnterOnUsernameField); } } @@ -299,16 +313,23 @@ private void OnKeyDownHandler(object sender, KeyEventArgs e) } else if (e.Key == Key.Enter) { - this.CleanUpHandlers(); - - this.tcs.TrySetResult(!ReferenceEquals(sender, this.PART_NegativeButton) - ? new LoginDialogData - { - Username = this.Username, - SecurePassword = this.PART_PasswordBox?.SecurePassword, - ShouldRemember = this.RememberCheckBoxChecked - } - : null!); + if (PART_TextBox != null && PART_TextBox.IsFocused && ChangeFocusWithEnterOnUsernameField) + { + PART_PasswordBox?.Focus(); + } + else + { + this.CleanUpHandlers(); + + this.tcs.TrySetResult(!ReferenceEquals(sender, this.PART_NegativeButton) + ? new LoginDialogData + { + Username = this.Username, + SecurePassword = this.PART_PasswordBox?.SecurePassword, + ShouldRemember = this.RememberCheckBoxChecked + } + : null!); + } e.Handled = true; } diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs index 884e280962..ade86bdf91 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs @@ -61,5 +61,7 @@ public LoginDialogSettings(MetroDialogSettings? source) public string RememberCheckBoxText { get; set; } = DefaultRememberCheckBoxText; public bool RememberCheckBoxChecked { get; set; } = false; + + public bool ChangeFocusWithEnterOnUsernameField { get; set; } = false; } } \ No newline at end of file From 247f75728e199ed0eb17c780406f51c33c5f0623 Mon Sep 17 00:00:00 2001 From: Vinicius Cunha Date: Thu, 31 Oct 2024 11:26:56 -0300 Subject: [PATCH 2/3] fix property names --- .../Controls/Dialogs/LoginDialog.cs | 16 ++++++++-------- .../Controls/Dialogs/LoginDialogSettings.cs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs index 4a2d3e8a6a..266d71d816 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs @@ -224,17 +224,17 @@ public bool RememberCheckBoxChecked set => this.SetValue(RememberCheckBoxCheckedProperty, BooleanBoxes.Box(value)); } - /// Identifies the dependency property. - public static readonly DependencyProperty ChangeFocusWithEnterOnUsernameFieldProperty - = DependencyProperty.Register(nameof(ChangeFocusWithEnterOnUsernameField), + /// Identifies the dependency property. + public static readonly DependencyProperty ChangeFocusOnUsernameFieldWithEnterProperty + = DependencyProperty.Register(nameof(ChangeFocusOnUsernameFieldWithEnter), typeof(bool), typeof(LoginDialog), new PropertyMetadata(default(bool))); - public bool ChangeFocusWithEnterOnUsernameField + public bool ChangeFocusOnUsernameFieldWithEnter { - get => (bool) this.GetValue(ChangeFocusWithEnterOnUsernameFieldProperty); - set => this.SetValue(ChangeFocusWithEnterOnUsernameFieldProperty, value); + get => (bool) this.GetValue(ChangeFocusOnUsernameFieldWithEnterProperty); + set => this.SetValue(ChangeFocusOnUsernameFieldWithEnterProperty, value); } #endregion DependencyProperties @@ -270,7 +270,7 @@ internal LoginDialog(MetroWindow? parentWindow, LoginDialogSettings? settings) this.SetCurrentValue(RememberCheckBoxVisibilityProperty, loginDialogSettings.RememberCheckBoxVisibility); this.SetCurrentValue(RememberCheckBoxTextProperty, loginDialogSettings.RememberCheckBoxText); this.SetCurrentValue(RememberCheckBoxCheckedProperty, loginDialogSettings.RememberCheckBoxChecked); - this.SetCurrentValue(ChangeFocusWithEnterOnUsernameFieldProperty, loginDialogSettings.ChangeFocusWithEnterOnUsernameField); + this.SetCurrentValue(ChangeFocusOnUsernameFieldWithEnterProperty, loginDialogSettings.ChangeFocusOnUsernameFieldWithEnter); } } @@ -313,7 +313,7 @@ private void OnKeyDownHandler(object sender, KeyEventArgs e) } else if (e.Key == Key.Enter) { - if (PART_TextBox != null && PART_TextBox.IsFocused && ChangeFocusWithEnterOnUsernameField) + if (PART_TextBox != null && PART_TextBox.IsFocused && ChangeFocusOnUsernameFieldWithEnter) { PART_PasswordBox?.Focus(); } diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs index ade86bdf91..f8625f1a1a 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs @@ -62,6 +62,6 @@ public LoginDialogSettings(MetroDialogSettings? source) public bool RememberCheckBoxChecked { get; set; } = false; - public bool ChangeFocusWithEnterOnUsernameField { get; set; } = false; + public bool ChangeFocusOnUsernameFieldWithEnter { get; set; } = false; } } \ No newline at end of file From f9059ba4cf3d3626613549b9c7575b65805a9ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Batista?= Date: Thu, 31 Oct 2024 20:49:04 -0300 Subject: [PATCH 3/3] Remove the initialization to the 'ChangeFocusOnUsernameFieldWithEnter' property --- src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs index f8625f1a1a..900f85ab94 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs @@ -62,6 +62,6 @@ public LoginDialogSettings(MetroDialogSettings? source) public bool RememberCheckBoxChecked { get; set; } = false; - public bool ChangeFocusOnUsernameFieldWithEnter { get; set; } = false; + public bool ChangeFocusOnUsernameFieldWithEnter { get; set; } } } \ No newline at end of file