@@ -224,6 +224,19 @@ public bool RememberCheckBoxChecked
224224 set => this . SetValue ( RememberCheckBoxCheckedProperty , BooleanBoxes . Box ( value ) ) ;
225225 }
226226
227+ /// <summary>Identifies the <see cref="ChangeFocusOnUsernameFieldWithEnterProperty"/> dependency property.</summary>
228+ public static readonly DependencyProperty ChangeFocusOnUsernameFieldWithEnterProperty
229+ = DependencyProperty . Register ( nameof ( ChangeFocusOnUsernameFieldWithEnter ) ,
230+ typeof ( bool ) ,
231+ typeof ( LoginDialog ) ,
232+ new PropertyMetadata ( default ( bool ) ) ) ;
233+
234+ public bool ChangeFocusOnUsernameFieldWithEnter
235+ {
236+ get => ( bool ) this . GetValue ( ChangeFocusOnUsernameFieldWithEnterProperty ) ;
237+ set => this . SetValue ( ChangeFocusOnUsernameFieldWithEnterProperty , value ) ;
238+ }
239+
227240 #endregion DependencyProperties
228241
229242 #region Constructor
@@ -257,6 +270,7 @@ internal LoginDialog(MetroWindow? parentWindow, LoginDialogSettings? settings)
257270 this . SetCurrentValue ( RememberCheckBoxVisibilityProperty , loginDialogSettings . RememberCheckBoxVisibility ) ;
258271 this . SetCurrentValue ( RememberCheckBoxTextProperty , loginDialogSettings . RememberCheckBoxText ) ;
259272 this . SetCurrentValue ( RememberCheckBoxCheckedProperty , loginDialogSettings . RememberCheckBoxChecked ) ;
273+ this . SetCurrentValue ( ChangeFocusOnUsernameFieldWithEnterProperty , loginDialogSettings . ChangeFocusOnUsernameFieldWithEnter ) ;
260274 }
261275 }
262276
@@ -299,16 +313,23 @@ private void OnKeyDownHandler(object sender, KeyEventArgs e)
299313 }
300314 else if ( e . Key == Key . Enter )
301315 {
302- this . CleanUpHandlers ( ) ;
303-
304- this . tcs . TrySetResult ( ! ReferenceEquals ( sender , this . PART_NegativeButton )
305- ? new LoginDialogData
306- {
307- Username = this . Username ,
308- SecurePassword = this . PART_PasswordBox ? . SecurePassword ,
309- ShouldRemember = this . RememberCheckBoxChecked
310- }
311- : null ! ) ;
316+ if ( PART_TextBox != null && PART_TextBox . IsFocused && ChangeFocusOnUsernameFieldWithEnter )
317+ {
318+ PART_PasswordBox ? . Focus ( ) ;
319+ }
320+ else
321+ {
322+ this . CleanUpHandlers ( ) ;
323+
324+ this . tcs . TrySetResult ( ! ReferenceEquals ( sender , this . PART_NegativeButton )
325+ ? new LoginDialogData
326+ {
327+ Username = this . Username ,
328+ SecurePassword = this . PART_PasswordBox ? . SecurePassword ,
329+ ShouldRemember = this . RememberCheckBoxChecked
330+ }
331+ : null ! ) ;
332+ }
312333
313334 e . Handled = true ;
314335 }
0 commit comments