@@ -30,6 +30,7 @@ public partial class Omnibar : Control
3030 private Popup ? _autoSuggestPopup ;
3131 private Border ? _autoSuggestBoxBorder ;
3232 private bool _isFocused ;
33+ private bool _stillHasFocus ;
3334
3435 public Omnibar ( )
3536 {
@@ -87,6 +88,7 @@ protected override void OnApplyTemplate()
8788
8889 GotFocus += Omnibar_GotFocus ;
8990 LostFocus += Omnibar_LostFocus ;
91+ LosingFocus += Omnibar_LosingFocus ;
9092
9193 UpdateVisualStates ( ) ;
9294
@@ -147,14 +149,25 @@ private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
147149 UpdateVisualStates ( ) ;
148150 }
149151
150- private void Omnibar_LostFocus ( object sender , RoutedEventArgs e )
152+ private void Omnibar_LosingFocus ( UIElement sender , LosingFocusEventArgs args )
151153 {
152154 // Ignore when user clicks on the TextBox or the button area of an OmnibarMode, Omnibar still has focus anyway
153- if ( e . OriginalSource . GetType ( ) is not { } originalSourceType ||
154- originalSourceType == typeof ( TextBox ) ||
155- originalSourceType == typeof ( OmnibarMode ) ||
156- originalSourceType == typeof ( Omnibar ) )
155+ if ( args . NewFocusedElement ? . GetType ( ) is not { } focusedType ||
156+ focusedType == typeof ( TextBox ) ||
157+ focusedType == typeof ( OmnibarMode ) ||
158+ focusedType == typeof ( Omnibar ) )
159+ {
160+ _stillHasFocus = true ;
161+ }
162+ }
163+
164+ private void Omnibar_LostFocus ( object sender , RoutedEventArgs e )
165+ {
166+ if ( _stillHasFocus )
167+ {
168+ _stillHasFocus = false ;
157169 return ;
170+ }
158171
159172 _isFocused = false ;
160173 UpdateVisualStates ( ) ;
0 commit comments