@ -42,6 +42,14 @@ namespace Avalonia.Input
public static readonly StyledProperty < Cursor ? > CursorProperty =
AvaloniaProperty . Register < InputElement , Cursor ? > ( nameof ( Cursor ) , null , true ) ;
/// <summary>
/// Defines the <see cref="IsKeyboardFocusWithin"/> property.
/// </summary>
public static readonly DirectProperty < InputElement , bool > IsKeyboardFocusWithinProperty =
AvaloniaProperty . RegisterDirect < InputElement , bool > (
nameof ( IsKeyboardFocusWithin ) ,
o = > o . IsKeyboardFocusWithin ) ;
/// <summary>
/// Defines the <see cref="IsFocused"/> property.
/// </summary>
@ -160,6 +168,7 @@ namespace Avalonia.Input
private bool _ isEffectivelyEnabled = true ;
private bool _ isFocused ;
private bool _ isKeyboardFocusWithin ;
private bool _ isFocusVisible ;
private bool _ isPointerOver ;
private GestureRecognizerCollection ? _ gestureRecognizers ;
@ -343,6 +352,15 @@ namespace Avalonia.Input
get { return GetValue ( CursorProperty ) ; }
set { SetValue ( CursorProperty , value ) ; }
}
/// <summary>
/// Gets a value indicating whether keyboard focus is anywhere within the element or its visual tree child elements.
/// </summary>
public bool IsKeyboardFocusWithin
{
get = > _ isKeyboardFocusWithin ;
internal set = > SetAndRaise ( IsKeyboardFocusWithinProperty , ref _ isKeyboardFocusWithin , value ) ;
}
/// <summary>
/// Gets a value indicating whether the control is focused.
@ -423,7 +441,7 @@ namespace Avalonia.Input
base . OnAttachedToVisualTreeCore ( e ) ;
UpdateIsEffectivelyEnabled ( ) ;
}
/// <summary>
/// Called before the <see cref="GotFocus"/> event occurs.
/// </summary>
@ -544,6 +562,10 @@ namespace Avalonia.Input
{
UpdatePseudoClasses ( null , change . NewValue . GetValueOrDefault < bool > ( ) ) ;
}
else if ( change . Property = = IsKeyboardFocusWithinProperty )
{
PseudoClasses . Set ( ":focus-within" , _ isKeyboardFocusWithin ) ;
}
}
/// <summary>