using Avalonia.Controls; using Avalonia.Input; using Avalonia.Threading; using Avalonia.Xaml.Interactivity; namespace Avalonia.Xaml.Interactions.Custom; /// /// Focuses the on event. /// public class FocusOnPointerMovedBehavior : StyledElementBehavior { /// protected override void OnAttachedToVisualTree() { if (AssociatedObject is not null) { AssociatedObject.PointerMoved += PointerMoved; } } /// protected override void OnDetachedFromVisualTree() { if (AssociatedObject is not null) { AssociatedObject.PointerMoved -= PointerMoved; } } private void PointerMoved(object? sender, PointerEventArgs args) { Dispatcher.UIThread.Post(() => AssociatedObject?.Focus()); } }