Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #152 from zii-dmg/patch-1
Browse files Browse the repository at this point in the history
Fixed FocusBehavior
  • Loading branch information
wieslawsoltes authored Apr 2, 2024
2 parents 4e04758 + a6d81d1 commit b5e0c13
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/Avalonia.Xaml.Interactions.Custom/FocusBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ public bool IsFocused
/// <param name="disposables"></param>
protected override void OnAttached(CompositeDisposable disposables)
{
base.OnAttached();
if (AssociatedObject is not null)
{
disposables.Add(AssociatedObject.GetObservable(Avalonia.Input.InputElement.IsFocusedProperty)
.Subscribe(new AnonymousObserver<bool>(
focused =>
{
if (!focused)
{
SetCurrentValue(IsFocusedProperty, false);
}
})));

if (AssociatedObject is not null)
{
AssociatedObject.AttachedToLogicalTree += (_, _) =>
disposables.Add(this.GetObservable(IsFocusedProperty)
.Subscribe(new AnonymousObserver<bool>(
focused =>
{
if (focused)
{
AssociatedObject.Focus();
}
})));
}
disposables.Add(this.GetObservable(IsFocusedProperty)
.Subscribe(new AnonymousObserver<bool>(
focused =>
{
if (focused)
{
AssociatedObject.Focus();
}
})));
}
}
}

0 comments on commit b5e0c13

Please sign in to comment.