|
|
@@ -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>
|