MainViewModel.cs 954 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Awsomeness.Core;
  2. using CommunityToolkit.Mvvm.ComponentModel;
  3. using CommunityToolkit.Mvvm.Input;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Awesomeness.GUI.ViewModels;
  10. partial class MainViewModel : ObservableObject
  11. {
  12. private Person _person;
  13. public MainViewModel()
  14. {
  15. _person = new Person();
  16. }
  17. [ObservableProperty]
  18. [NotifyCanExecuteChangedFor(nameof(ResetNameCommand))]
  19. private string firstName = String.Empty;
  20. [RelayCommand(CanExecute = nameof(CanResetName))]
  21. private void ResetName()
  22. {
  23. FirstName = String.Empty;
  24. }
  25. private bool CanResetName()
  26. {
  27. return FirstName != String.Empty;
  28. }
  29. [RelayCommand]
  30. private void SetName()
  31. {
  32. _person.FirstName = FirstName;
  33. }
  34. [RelayCommand]
  35. private void GetName()
  36. {
  37. FirstName = _person.FirstName;
  38. }
  39. }