Set focus away on when activating autoclose item
MODIFY
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
@@ -104,7 +104,7 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : AttachedToVisualTreeBehavio
return isFocused
.Buffer(TimeSpan.FromSeconds(0.1))
.Where(focusedList => focusedList.Any())
- .Select(focusedList => focusedList.Any(focused => focused))
+ .Select(focusedList => focusedList.Last())
.DistinctUntilChanged()
.ObserveOn(RxApp.MainThreadScheduler)
.Do(isOpen => IsFlyoutOpen = isOpen)

ADD
WalletWasabi.Fluent/ViewModels/SearchBar/CloseSearchBarMessage.cs
+namespace WalletWasabi.Fluent.ViewModels.SearchBar;
+
+public class CloseSearchBarMessage
+{
+}

MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/SearchBarViewModel.cs
WalletWasabi.Fluent/ViewModels/SearchBar/SearchBarViewModel.cs
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
+using Avalonia.Controls.ApplicationLifetimes;
using DynamicData;
using DynamicData.Aggregation;
using ReactiveUI;
@@ -30,7 +31,7 @@ public partial class SearchBarViewModel : ReactiveObject
filteredItems
.Transform(
item => item is ActionableItem i
- ? new AutocloseActionableItem(i, () => IsSearchListVisible = false)
+ ? new AutocloseActionableItem(i, () => MessageBus.Current.SendMessage(new CloseSearchBarMessage()))
: item)
.Group(s => s.Category)
.Transform(group => new SearchItemGroup(group.Key, group.Cache))

MODIFY
WalletWasabi.Fluent/Views/SearchBar/SearchBar.axaml.cs
WalletWasabi.Fluent/Views/SearchBar/SearchBar.axaml.cs
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
+using ReactiveUI;
+using WalletWasabi.Fluent.ViewModels.SearchBar;
namespace WalletWasabi.Fluent.Views.SearchBar;
public class SearchBar : UserControl
{
+ private readonly CompositeDisposable _disposables = new();
+
public SearchBar()
{
InitializeComponent();
}
+ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
+ {
+ MessageBus.Current
+ .Listen<CloseSearchBarMessage>()
+ .Do(_ => FocusMainWindow())
+ .Subscribe()
+ .DisposeWith(_disposables);
+ }
+
+ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
+ {
+ _disposables.Dispose();
+ }
+
+ private static void FocusMainWindow()
+ {
+ if (Application.Current is { ApplicationLifetime: IClassicDesktopStyleApplicationLifetime applicationLifetime })
+ {
+ applicationLifetime.MainWindow.Focus();
+ }
+ }
+
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);

Set focus away on when activating autoclose item