diff --git a/src/Avalonia.Base/Input/InputElement.cs b/src/Avalonia.Base/Input/InputElement.cs index a3c7e72ca9..b5e31b0309 100644 --- a/src/Avalonia.Base/Input/InputElement.cs +++ b/src/Avalonia.Base/Input/InputElement.cs @@ -211,8 +211,8 @@ namespace Avalonia.Input { IsEnabledProperty.Changed.Subscribe(IsEnabledChanged); - GotFocusEvent.AddClassHandler((x, e) => x.OnGotFocus(e)); - LostFocusEvent.AddClassHandler((x, e) => x.OnLostFocus(e)); + GotFocusEvent.AddClassHandler((x, e) => x.OnGotFocusCore(e)); + LostFocusEvent.AddClassHandler((x, e) => x.OnLostFocusCore(e)); KeyDownEvent.AddClassHandler((x, e) => x.OnKeyDown(e)); KeyUpEvent.AddClassHandler((x, e) => x.OnKeyUp(e)); TextInputEvent.AddClassHandler((x, e) => x.OnTextInput(e)); @@ -535,31 +535,41 @@ namespace Avalonia.Input UpdateIsEffectivelyEnabled(); } - /// - /// Called before the event occurs. - /// - /// The event args. - protected virtual void OnGotFocus(GotFocusEventArgs e) + private void OnGotFocusCore(GotFocusEventArgs e) { var isFocused = e.Source == this; _isFocusVisible = isFocused && (e.NavigationMethod == NavigationMethod.Directional || e.NavigationMethod == NavigationMethod.Tab); IsFocused = isFocused; + OnGotFocus(e); } /// - /// Called before the event occurs. + /// Invoked when an unhandled reaches an element in its + /// route that is derived from this class. Implement this method to add class handling + /// for this event. /// - /// The event args. - protected virtual void OnLostFocus(RoutedEventArgs e) + /// Data about the event. + protected virtual void OnGotFocus(GotFocusEventArgs e) + { + } + + private void OnLostFocusCore(RoutedEventArgs e) { _isFocusVisible = false; IsFocused = false; + OnLostFocus(e); } /// - /// Called before the event occurs. + /// Invoked when an unhandled reaches an element in its + /// route that is derived from this class. Implement this method to add class handling + /// for this event. /// - /// The event args. + /// Data about the event. + protected virtual void OnLostFocus(RoutedEventArgs e) + { + } + /// /// Invoked when an unhandled reaches an element in its /// route that is derived from this class. Implement this method to add class handling