From a6d81d15ca745c9629db07aebda4ffba61d306f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 2 Apr 2024 23:10:57 +0200 Subject: [PATCH] Update FocusBehavior.cs --- .../FocusBehavior.cs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Avalonia.Xaml.Interactions.Custom/FocusBehavior.cs b/src/Avalonia.Xaml.Interactions.Custom/FocusBehavior.cs index 3786e5f2..b367fbcc 100644 --- a/src/Avalonia.Xaml.Interactions.Custom/FocusBehavior.cs +++ b/src/Avalonia.Xaml.Interactions.Custom/FocusBehavior.cs @@ -31,27 +31,27 @@ public bool IsFocused /// protected override void OnAttached(CompositeDisposable disposables) { - if (AssociatedObject is not null) - { - disposables.Add(AssociatedObject.GetObservable(Avalonia.Input.InputElement.IsFocusedProperty) - .Subscribe(new AnonymousObserver( - focused => - { - if (!focused) - { - IsFocused = false; - } - }))); + if (AssociatedObject is not null) + { + disposables.Add(AssociatedObject.GetObservable(Avalonia.Input.InputElement.IsFocusedProperty) + .Subscribe(new AnonymousObserver( + focused => + { + if (!focused) + { + SetCurrentValue(IsFocusedProperty, false); + } + }))); - disposables.Add(this.GetObservable(IsFocusedProperty) - .Subscribe(new AnonymousObserver( - focused => - { - if (focused) - { - AssociatedObject.Focus(); - } - }))); - } + disposables.Add(this.GetObservable(IsFocusedProperty) + .Subscribe(new AnonymousObserver( + focused => + { + if (focused) + { + AssociatedObject.Focus(); + } + }))); + } } }