Simplify how the ReceiveTab textblock gets focused.
ADD
WalletWasabi.Gui/Behaviors/FocusBehavior.cs
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Xaml.Interactivity;
+using System;
+using System.Reactive.Disposables;
+
+namespace WalletWasabi.Gui.Behaviors
+{
+ class FocusBehavior : Behavior<Control>
+ {
+ private CompositeDisposable _disposables = new CompositeDisposable();
+ private Control _attachedControl;
+
+ static readonly AvaloniaProperty<bool> IsFocusedProperty =
+ AvaloniaProperty.Register<FocusBehavior, bool>(nameof(IsFocused), defaultBindingMode: Avalonia.Data.BindingMode.TwoWay);
+
+ public bool IsFocused
+ {
+ get => GetValue(IsFocusedProperty);
+ set => SetValue(IsFocusedProperty, value);
+ }
+
+ protected override void OnAttached()
+ {
+ base.OnAttached();
+
+ AssociatedObject.AttachedToLogicalTree += (sender, e) =>
+ {
+ _disposables.Add(this.GetObservable(IsFocusedProperty).Subscribe(focused =>
+ {
+ if (focused)
+ {
+ AssociatedObject.Focus();
+ }
+ }));
+ };
+ }
+
+ protected override void OnDetaching()
+ {
+ base.OnDetaching();
+
+ _disposables.Dispose();
+ }
+ }
+}

DELETE
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/Controls/WalletExplorer/ReceiveTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:iac="clr-namespace:Avalonia.Xaml.Interactions.Custom;assembly=Avalonia.Xaml.Interactions.Custom"
xmlns:controls="clr-namespace:WalletWasabi.Gui.Controls;assembly=WalletWasabi.Gui"
- Name="ReceiveTabViewerUserControl"
- IsVisible="{Binding IsSelected}">
+ Name="ReceiveTabViewerUserControl">
<i:Interaction.Behaviors>
<behaviors:ClearPropertyOnLostFocusBehavior TargetProperty="{Binding SelectedAddress}" />
</i:Interaction.Behaviors>
<TextBox Text="{Binding Label, Mode=TwoWay}" Watermark="Label (Required)" UseFloatingWatermark="True" Grid.Column="0" Margin="0 0 10 0">
<i:Interaction.Behaviors>
<behaviors:CommandOnEnterBehavior Command="{Binding GenerateCommand}" />
- <behaviors:FocusOnVisibleBehavior AttachedControlName="ReceiveTabViewerUserControl" />
+ <behaviors:FocusBehavior IsFocused="{Binding IsSelected}" />
<iac:FocusOnAttachedToVisualTreeBehavior />
</i:Interaction.Behaviors>

Simplify how the ReceiveTab textblock gets focused.