@@ -63,23 +63,32 @@ private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
63
63
64
64
public async Task SetHotkeyAsync ( HotkeyModel keyModel , bool triggerValidate = true )
65
65
{
66
- CurrentHotkey = keyModel ;
67
-
68
- tbHotkey . Text = CurrentHotkey . ToString ( ) ;
66
+ tbHotkey . Text = keyModel . ToString ( ) ;
69
67
tbHotkey . Select ( tbHotkey . Text . Length , 0 ) ;
70
68
71
69
if ( triggerValidate )
72
70
{
73
71
bool hotkeyAvailable = CheckHotkeyAvailability ( keyModel ) ;
72
+ CurrentHotkeyAvailable = hotkeyAvailable ;
74
73
SetMessage ( hotkeyAvailable ) ;
75
74
OnHotkeyChanged ( ) ;
76
75
77
76
var token = hotkeyUpdateSource . Token ;
78
77
await Task . Delay ( 500 , token ) ;
79
78
if ( token . IsCancellationRequested )
80
79
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 ;
83
92
}
84
93
}
85
94
@@ -94,7 +103,7 @@ public Task SetHotkeyAsync(string keyStr, bool triggerValidate = true)
94
103
95
104
private void tbHotkey_LostFocus ( object sender , RoutedEventArgs e )
96
105
{
97
-
106
+
98
107
}
99
108
100
109
private void tbHotkey_GotFocus ( object sender , RoutedEventArgs e )
0 commit comments