Fix SearchBar remains focused and flyout stays closed on OS app switch
MODIFY
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
@@ -17,8 +17,7 @@ namespace WalletWasabi.Fluent.Behaviors;
public class ShowAttachedFlyoutWhenFocusedBehavior : Behavior<Control>
{
public static readonly StyledProperty<bool> IsFlyoutOpenProperty =
- AvaloniaProperty.Register<ShowAttachedFlyoutWhenFocusedBehavior, bool>(
- nameof(IsFlyoutOpen));
+ AvaloniaProperty.Register<ShowAttachedFlyoutWhenFocusedBehavior, bool>(nameof(IsFlyoutOpen));
private readonly CompositeDisposable _disposables = new();
@@ -55,7 +54,8 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : Behavior<Control>
DescendantPressed(visualRoot)
.Select(descendant => AssociatedObject.IsVisualAncestorOf(descendant))
- .Do(isAncestor =>
+ .Do(
+ isAncestor =>
{
_flyoutController.IsOpen = isAncestor;
IsFlyoutOpen = isAncestor;
@@ -64,7 +64,8 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : Behavior<Control>
.DisposeWith(_disposables);
Observable.FromEventPattern(AssociatedObject, nameof(InputElement.GotFocus))
- .Do(_ =>
+ .Do(
+ _ =>
{
_flyoutController.IsOpen = true;
IsFlyoutOpen = true;
@@ -72,9 +73,22 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : Behavior<Control>
.Subscribe()
.DisposeWith(_disposables);
+ Observable.FromEventPattern(visualRoot, nameof(Window.Activated))
+ .Do(
+ _ =>
+ {
+ if (AssociatedObject.IsFocused)
+ {
+ _flyoutController.IsOpen = true;
+ }
+ })
+ .Subscribe()
+ .DisposeWith(_disposables);
+
Observable.FromEventPattern(AssociatedObject, nameof(InputElement.LostFocus))
.Where(_ => !IsFocusInside(flyoutBase))
- .Do(_ =>
+ .Do(
+ _ =>
{
_flyoutController.IsOpen = false;
IsFlyoutOpen = false;

Fix SearchBar remains focused and flyout stays closed on OS app switch