using Avalonia.Controls; using Avalonia.Threading; using Avalonia.Xaml.Interactivity; namespace Avalonia.Xaml.Interactions.Custom; /// /// Focuses the when attached to visual tree. /// public class FocusOnAttachedToVisualTreeBehavior : StyledElementBehavior { /// protected override void OnAttachedToVisualTree() { Dispatcher.UIThread.Post(() => AssociatedObject?.Focus()); } }