@@ -63,23 +63,32 @@ private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
6363
6464 public async Task SetHotkeyAsync ( HotkeyModel keyModel , bool triggerValidate = true )
6565 {
66- CurrentHotkey = keyModel ;
67-
68- tbHotkey . Text = CurrentHotkey . ToString ( ) ;
66+ tbHotkey . Text = keyModel . ToString ( ) ;
6967 tbHotkey . Select ( tbHotkey . Text . Length , 0 ) ;
7068
7169 if ( triggerValidate )
7270 {
7371 bool hotkeyAvailable = CheckHotkeyAvailability ( keyModel ) ;
72+ CurrentHotkeyAvailable = hotkeyAvailable ;
7473 SetMessage ( hotkeyAvailable ) ;
7574 OnHotkeyChanged ( ) ;
7675
7776 var token = hotkeyUpdateSource . Token ;
7877 await Task . Delay ( 500 , token ) ;
7978 if ( token . IsCancellationRequested )
8079 return ;
81- FocusManager . SetFocusedElement ( FocusManager . GetFocusScope ( this ) , null ) ;
82- Keyboard . ClearFocus ( ) ;
80+
81+ if ( CurrentHotkeyAvailable )
82+ {
83+ CurrentHotkey = keyModel ;
84+ // To trigger LostFocus
85+ FocusManager . SetFocusedElement ( FocusManager . GetFocusScope ( this ) , null ) ;
86+ Keyboard . ClearFocus ( ) ;
87+ }
88+ }
89+ else
90+ {
91+ CurrentHotkey = keyModel ;
8392 }
8493 }
8594
@@ -94,7 +103,7 @@ public Task SetHotkeyAsync(string keyStr, bool triggerValidate = true)
94103
95104 private void tbHotkey_LostFocus ( object sender , RoutedEventArgs e )
96105 {
97-
106+
98107 }
99108
100109 private void tbHotkey_GotFocus ( object sender , RoutedEventArgs e )
0 commit comments