@@ -224,6 +224,19 @@ public bool RememberCheckBoxChecked
224
224
set => this . SetValue ( RememberCheckBoxCheckedProperty , BooleanBoxes . Box ( value ) ) ;
225
225
}
226
226
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
+
227
240
#endregion DependencyProperties
228
241
229
242
#region Constructor
@@ -257,6 +270,7 @@ internal LoginDialog(MetroWindow? parentWindow, LoginDialogSettings? settings)
257
270
this . SetCurrentValue ( RememberCheckBoxVisibilityProperty , loginDialogSettings . RememberCheckBoxVisibility ) ;
258
271
this . SetCurrentValue ( RememberCheckBoxTextProperty , loginDialogSettings . RememberCheckBoxText ) ;
259
272
this . SetCurrentValue ( RememberCheckBoxCheckedProperty , loginDialogSettings . RememberCheckBoxChecked ) ;
273
+ this . SetCurrentValue ( ChangeFocusOnUsernameFieldWithEnterProperty , loginDialogSettings . ChangeFocusOnUsernameFieldWithEnter ) ;
260
274
}
261
275
}
262
276
@@ -299,16 +313,23 @@ private void OnKeyDownHandler(object sender, KeyEventArgs e)
299
313
}
300
314
else if ( e . Key == Key . Enter )
301
315
{
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
+ }
312
333
313
334
e . Handled = true ;
314
335
}
0 commit comments