diff --git a/Wallet.Avalonia/CreateWalletView.axaml b/Wallet.Avalonia/CreateWalletView.axaml index 6048cef..c1a5fd9 100644 --- a/Wallet.Avalonia/CreateWalletView.axaml +++ b/Wallet.Avalonia/CreateWalletView.axaml @@ -2,29 +2,56 @@ x:Class="Wallet.Avalonia.CreateWalletView" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:vm="using:Wallet" - Title="Create Wallet" + Title="Create a new wallet" x:DataType="vm:CreateWalletViewModel" CloseButtonText="Cancel" - IsPrimaryButtonEnabled="{Binding !Active}" - IsSecondaryButtonEnabled="{Binding !Active}" + DefaultButton="Primary" PrimaryButtonText="Create"> + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + Name, [new ValidationRule(() => Name is { Length: > 0 })], + ValidationTrigger.Immediate); + + Validation.Add(() => Password, [new ValidationRule(() => Password is { Length: > 0 })], + ValidationTrigger.Immediate); + + Name = name; + } + public async Task ConfirmPrimary() { using (await new ActivityLock(this)) @@ -30,4 +50,14 @@ public partial class CreateWalletViewModel(IServiceProvider provider, bool>(Create.As(new Wallet<(string, string)>((Name, Password)))); } } + + protected override void OnPropertyChanged(PropertyChangedEventArgs args) + { + if (args.PropertyName is string name) + { + Validation.Validate(name); + } + + base.OnPropertyChanged(args); + } } \ No newline at end of file diff --git a/Wallet/OpenWalletViewModel.cs b/Wallet/OpenWalletViewModel.cs index d3f0328..51bf381 100644 --- a/Wallet/OpenWalletViewModel.cs +++ b/Wallet/OpenWalletViewModel.cs @@ -1,25 +1,37 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using System.ComponentModel.DataAnnotations; using Toolkit.Foundation; namespace Wallet; -public partial class OpenWalletViewModel(IServiceProvider provider, - IServiceFactory factory, - IMediator mediator, - IPublisher publisher, - ISubscriber subscriber, - IDisposer disposer, - string name) : - Observable(provider, factory, mediator, publisher, subscriber, disposer) +public partial class OpenWalletViewModel : Observable { + private readonly IValidation validation; + [ObservableProperty] - private string? name = name; + private string? name; [ObservableProperty] private string? password; + + [ObservableProperty] + private string? repeatedPassword; + + public OpenWalletViewModel(IValidation validation, + IServiceProvider provider, + IServiceFactory factory, + IMediator mediator, + IPublisher publisher, + ISubscriber subscriber, + IDisposer disposer, + string name) : base(provider, factory, mediator, publisher, subscriber, disposer) + { + this.validation = validation; + + Name = name; + } + [RelayCommand] private async Task Invoke() {