introduce CharsetViewModel
ADD
WalletWasabi.Fluent/ViewModels/Login/PasswordFinder/CharsetViewModel.cs
+using System.Globalization;
+using System.Windows.Input;
+using ReactiveUI;
+using WalletWasabi.Extensions;
+using WalletWasabi.Wallets.PasswordFinder;
+
+namespace WalletWasabi.Fluent.ViewModels.Login.PasswordFinder;
+
+public class CharsetViewModel : ViewModelBase
+{
+ public CharsetViewModel(SelectCharsetViewModel owner, Charset charset)
+ {
+ Title = charset.FriendlyName();
+ ShortTitle = charset.ToString().ToUpper(CultureInfo.InvariantCulture);
+ Characters = PasswordFinderHelper.Charsets.TryGetValue(charset, out var characters) ? characters : "";
+
+ SelectCommand = ReactiveCommand.Create(() =>
+ {
+ owner.Options.Charset = charset;
+ owner.Navigate().To(new ContainsNumbersViewModel(owner.Options));
+ });
+ }
+
+ public string Title { get; }
+
+ public string ShortTitle { get; }
+
+ public string Characters { get; }
+
+ public ICommand SelectCommand { get; }
+}

MODIFY
WalletWasabi.Fluent/ViewModels/Login/PasswordFinder/SelectCharsetViewModel.cs
WalletWasabi.Fluent/ViewModels/Login/PasswordFinder/SelectCharsetViewModel.cs
using System.Collections.Generic;
using System.Linq;
-using System.Reactive.Linq;
-using ReactiveUI;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets.PasswordFinder;
@@ -10,31 +8,17 @@ namespace WalletWasabi.Fluent.ViewModels.Login.PasswordFinder;
[NavigationMetaData(Title = "Password Finder")]
public partial class SelectCharsetViewModel : RoutableViewModel
{
- [AutoNotify] private Charset? _selectedCharset;
-
public SelectCharsetViewModel(PasswordFinderOptions options)
{
- Title = "Password Finder";
-
+ Options = options;
SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
EnableBack = true;
- this.WhenAnyValue(x => x.SelectedCharset)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(x =>
- {
- if (x is null)
- {
- return;
+ Charsets = Enum.GetValues(typeof(Charset)).Cast<Charset>().Select(x => new CharsetViewModel(this, x));
}
- options.Charset = (Charset)x;
- Navigate().To(new ContainsNumbersViewModel(options));
-
- SelectedCharset = null;
- });
- }
+ public PasswordFinderOptions Options { get; }
- public IEnumerable<Charset> Charsets => Enum.GetValues(typeof(Charset)).Cast<Charset>();
+ public IEnumerable<CharsetViewModel> Charsets { get; }
}

MODIFY
WalletWasabi.Fluent/Views/Login/PasswordFinder/SelectCharsetView.axaml
WalletWasabi.Fluent/Views/Login/PasswordFinder/SelectCharsetView.axaml
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:i="using:Avalonia.Xaml.Interactivity"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WalletWasabi.Fluent.ViewModels.Login.PasswordFinder"
xmlns:c="using:WalletWasabi.Fluent.Controls"
- xmlns:conv="using:WalletWasabi.Fluent.Converters"
- xmlns:behaviors="using:WalletWasabi.Fluent.Behaviors"
mc:Ignorable="d" d:DesignWidth="428" d:DesignHeight="371"
x:DataType="vm:SelectCharsetViewModel"
x:CompileBindings="True"
EnableNext="False">
<ListBox Items="{Binding Charsets}"
- SelectedItem="{Binding SelectedCharset}"
Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
</Style>
</ListBox.Styles>
<ListBox.ItemTemplate>
- <DataTemplate>
- <c:TileButton Text="{Binding Converter={x:Static conv:EnumConverters.ToFriendlyName}}"
+ <DataTemplate x:DataType="vm:CharsetViewModel">
+ <c:TileButton Text="{Binding Title}"
IconSize="60" Margin="10 10 10 20" Classes="bottomtext"
- ToolTip.Tip="{Binding Converter={x:Static conv:EnumConverters.ToCharset}}">
- <i:Interaction.Behaviors>
- <behaviors:ButtonInsideListBoxItemBehavior />
- </i:Interaction.Behaviors>
-
+ ToolTip.Tip="{Binding Characters}"
+ Command="{Binding SelectCommand}">
<Viewbox>
- <TextBlock FontSize="50" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Converter={x:Static conv:EnumConverters.ToUpperCase}}"
+ <TextBlock FontSize="50" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding ShortTitle}"
Foreground="{DynamicResource SystemAccentColor}" />
</Viewbox>
</c:TileButton>

introduce CharsetViewModel