SignUpView.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Reactive.Disposables;
  3. using Avalonia.ReactiveUI;
  4. using Generators.Sandbox.ViewModels;
  5. using ReactiveUI;
  6. using ReactiveUI.Validation.Extensions;
  7. using ReactiveUI.Validation.Formatters;
  8. namespace Generators.Sandbox.Controls;
  9. /// <summary>
  10. /// This is a sample view class with typed x:Name references generated using
  11. /// .NET 5 source generators. The class has to be partial because x:Name
  12. /// references are living in a separate partial class file. See also:
  13. /// https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/
  14. /// </summary>
  15. public partial class SignUpView : ReactiveUserControl<SignUpViewModel>
  16. {
  17. public SignUpView()
  18. {
  19. // The InitializeComponent method is also generated automatically
  20. // and lives in the autogenerated part of the partial class.
  21. InitializeComponent();
  22. this.WhenActivated(disposables =>
  23. {
  24. this.Bind(ViewModel, x => x.UserName, x => x.UserNameTextBox.Text)
  25. .DisposeWith(disposables);
  26. this.Bind(ViewModel, x => x.Password, x => x.PasswordTextBox.Text)
  27. .DisposeWith(disposables);
  28. this.Bind(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordTextBox.Text)
  29. .DisposeWith(disposables);
  30. this.BindCommand(ViewModel, x => x.SignUp, x => x.SignUpButton)
  31. .DisposeWith(disposables);
  32. this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text)
  33. .DisposeWith(disposables);
  34. this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text)
  35. .DisposeWith(disposables);
  36. this.BindValidation(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordValidation.Text)
  37. .DisposeWith(disposables);
  38. var newLineFormatter = new SingleLineFormatter(Environment.NewLine);
  39. this.BindValidation(ViewModel, x => x.CompoundValidation.Text, newLineFormatter)
  40. .DisposeWith(disposables);
  41. // The references to text boxes below are also auto generated.
  42. // Use Ctrl+Click in order to view the generated sources.
  43. UserNameTextBox.Text = "Joseph!";
  44. PasswordTextBox.Text = "1234";
  45. ConfirmPasswordTextBox.Text = "1234";
  46. SignUpButtonDescription.Text = "Press the button below to sign up.";
  47. });
  48. }
  49. }