better focus handeling
MODIFY
WalletWasabi.Fluent/Models/RecoveryWord.cs
WalletWasabi.Fluent/Models/RecoveryWord.cs
-using Avalonia.Input;
using ReactiveUI;
-using System;
-using System.Collections.Generic;
-using System.Text;
using WalletWasabi.Gui.Validation;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Models;

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/CreateWallet/ConfirmRecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/CreateWallet/ConfirmRecoveryWordsViewModel.cs
@@ -15,7 +15,7 @@ using WalletWasabi.Gui.ViewModels;
namespace WalletWasabi.Fluent.ViewModels.Dialogs.CreateWallet
{
- public class ConfirmRecoveryWordsViewModel : ViewModelBase, IRoutableViewModel
+ public class ConfirmRecoveryWordsViewModel : ViewModelBase, IDisposable, IRoutableViewModel
{
private bool _isConfirmationFinished;
@@ -42,6 +42,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs.CreateWallet
get => _isConfirmationFinished;
set => this.RaiseAndSetIfChanged(ref _isConfirmationFinished, value);
}
+
public string UrlPathSegment { get; }
public IScreen HostScreen { get; }
public ObservableCollection<RecoveryWord> ConfirmationWords { get; }
@@ -49,40 +50,38 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs.CreateWallet
public ICommand CancelCommand { get; }
public ICommand GoBackCommand => HostScreen.Router.NavigateBack;
-
private void OnConfirmationWordCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (RecoveryWord item in e.NewItems)
{
- item.PropertyChanged += JumpFocus;
+ item.PropertyChanged += RecoveryWordOnPropertyChanged;
}
}
}
- private void JumpFocus(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == nameof(RecoveryWord.IsConfirmed))
+ private void RecoveryWordOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- // This will prevent that case when the control only once can get the focus
- foreach (var item in ConfirmationWords.Where(x => !x.IsConfirmed))
+ if (e.PropertyName == nameof(RecoveryWord.IsConfirmed) && FocusManager.Instance.Current is { } focusManager && sender is RecoveryWord recoveryWord)
{
- item.IsFocused = false;
- }
+ var nextToFocus = KeyboardNavigationHandler.GetNext(focusManager, NavigationDirection.Next);
+ var prevToFocus = KeyboardNavigationHandler.GetNext(focusManager, NavigationDirection.Previous);
- // Find the next control
- var nextToFocus = ConfirmationWords.FirstOrDefault(x => x.IsConfirmed == false);
+ var currentWordIndex = recoveryWord.Index;
- if (nextToFocus is { })
+ if (ConfirmationWords.Where(x => !x.IsConfirmed).Any(x => x.Index < currentWordIndex))
+ {
+ prevToFocus?.Focus();
+ }
+ else if (ConfirmationWords.Where(x => !x.IsConfirmed).Any(x => x.Index > currentWordIndex))
{
- // Give the focus to the next TextBlock
- nextToFocus.IsFocused = true;
+ nextToFocus?.Focus();
}
else
{
- // All word is confirmed, give the focus to the finish button
IsConfirmationFinished = true;
+ nextToFocus?.Focus();
}
}
}
@@ -114,5 +113,15 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs.CreateWallet
ConfirmationWords.Add(item);
}
}
+
+ public void Dispose()
+ {
+ foreach (RecoveryWord item in ConfirmationWords)
+ {
+ item.PropertyChanged -= RecoveryWordOnPropertyChanged;
+ }
+
+ ConfirmationWords.CollectionChanged -= OnConfirmationWordCollectionChanged;
+ }
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/Dialogs/CreateWallet/ConfirmRecoveryWordsView.axaml
WalletWasabi.Fluent/Views/Dialogs/CreateWallet/ConfirmRecoveryWordsView.axaml
<StackPanel Margin="0 0 0 20">
<TextBlock Text="{Binding Index, StringFormat=Recovery word {0}}" Margin="0 0 0 8" />
<StackPanel Orientation="Horizontal">
- <TextBox Watermark="Type the word here..." Text="{Binding Input}" IsEnabled="{Binding !IsConfirmed}" Width="280" FontSize="12">
- <i:Interaction.Behaviors>
- <behaviors:FocusBehavior IsFocused="{Binding IsFocused}"/>
- </i:Interaction.Behaviors>
- </TextBox>
+ <TextBox Watermark="Type the word here..." Text="{Binding Input}" IsEnabled="{Binding !IsConfirmed}" Width="280" FontSize="12" />
<PathIcon Foreground="{StaticResource SystemAccentColor}" IsVisible="{Binding IsConfirmed}" Data="{StaticResource checkmark_filled}" VerticalAlignment="Center" Width="12" Height="12" Margin="15 0 0 0" />
</StackPanel>
</StackPanel>
</c:ContentArea>
<Button Content="Cancel" Margin="31 0 0 20" Command="{Binding CancelCommand}" Classes="invisible" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
- <Button Content="Finish" Margin="0 0 25 20" Command="{Binding FinishCommand}" IsEnabled="{Binding IsConfirmationFinished}" Classes="action" HorizontalAlignment="Right" VerticalAlignment="Bottom">
- <i:Interaction.Behaviors>
- <behaviors:FocusBehavior IsFocused="{Binding IsConfirmationFinished}"/>
- </i:Interaction.Behaviors>
- </Button>
+ <Button Content="Finish" Margin="0 0 25 20" Command="{Binding FinishCommand}" IsEnabled="{Binding IsConfirmationFinished}" Classes="action" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Panel>
</UserControl>
\ No newline at end of file

better focus handeling