using Avalonia.Controls; using Avalonia.Input; using Avalonia.Threading; namespace Avalonia.Xaml.Interactions.Custom; /// /// /// public abstract class FocusBehaviorBase : AttachedToVisualTreeBehavior { /// /// /// public static readonly StyledProperty NavigationMethodProperty = AvaloniaProperty.Register(nameof(NavigationMethod)); /// /// /// public static readonly StyledProperty KeyModifiersProperty = AvaloniaProperty.Register(nameof(KeyModifiers)); /// /// /// public NavigationMethod NavigationMethod { get => GetValue(NavigationMethodProperty); set => SetValue(NavigationMethodProperty, value); } /// /// /// public KeyModifiers KeyModifiers { get => GetValue(KeyModifiersProperty); set => SetValue(KeyModifiersProperty, value); } /// /// /// /// protected virtual bool Focus() { if (!IsEnabled) { return false; } Dispatcher.UIThread.Post(() => AssociatedObject?.Focus(NavigationMethod, KeyModifiers)); return true; } }