Set focus on Label when tab is visible
ADD
WalletWasabi.Gui/Behaviors/FocusOnVisibleBehavior.cs
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Xaml.Interactivity;
+using System;
+using System.Collections.Generic;
+using System.Reactive.Disposables;
+using System.Text;
+
+namespace WalletWasabi.Gui.Behaviors
+{
+ class FocusOnVisibleBehavior : Behavior<Control>
+ {
+ private CompositeDisposable _disposables = new CompositeDisposable();
+ private Control _attachedControl;
+
+ static readonly AvaloniaProperty<string> AttachedControlNameProperty = AvaloniaProperty.Register<FocusOnVisibleBehavior, string>(nameof(AttachedControlName));
+
+ public string AttachedControlName
+ {
+ get { return GetValue(AttachedControlNameProperty); }
+ set { SetValue(AttachedControlNameProperty, value); }
+ }
+
+ protected override void OnAttached()
+ {
+ base.OnAttached();
+
+ AssociatedObject.AttachedToLogicalTree += (sender, e) =>
+ {
+ if (!string.IsNullOrEmpty(AttachedControlName))
+ {
+ _attachedControl = AssociatedObject.FindControl<Control>(AttachedControlName);
+
+ if(_attachedControl == null)
+ {
+ throw new Exception($"Control: {AttachedControlName} was not found on the control.");
+ }
+
+ _disposables.Add(_attachedControl.GetObservable(Control.IsVisibleProperty).Subscribe(visible =>
+ {
+ if (visible)
+ {
+ AssociatedObject.Focus();
+ }
+ }));
+ }
+ else
+ {
+ _disposables.Add(AssociatedObject.GetObservable(Control.IsVisibleProperty).Subscribe(visible =>
+ {
+ if (visible)
+ {
+ AssociatedObject.Focus();
+ }
+ }));
+ }
+ };
+ }
+
+ protected override void OnDetaching()
+ {
+ base.OnDetaching();
+
+ _disposables.Dispose();
+ }
+ }
+}

MODIFY
WalletWasabi.Gui/ViewModels/WasabiDocumentTabViewModel.cs
WalletWasabi.Gui/ViewModels/WasabiDocumentTabViewModel.cs
using AvalonStudio.Extensibility;
using AvalonStudio.Shell;
using Dock.Model;
+using ReactiveUI;
namespace WalletWasabi.Gui.ViewModels
{
@@ -22,18 +23,28 @@ namespace WalletWasabi.Gui.ViewModels
public double Width { get; set; }
public double Height { get; set; }
public IView Parent { get; set; }
+ private bool _isSelected;
+
+ public bool IsSelected
+ {
+ get { return _isSelected; }
+ set { this.RaiseAndSetIfChanged(ref _isSelected, value); }
+ }
public virtual void Close()
{
IoC.Get<IShell>().RemoveDocument(this);
+ this.IsSelected = false;
}
public virtual void OnSelected()
{
+ this.IsSelected = true;
}
public virtual void OnDeselected()
{
+ this.IsSelected = false;
}
}
}

Set focus on Label when tab is visible