AddCertificationControl.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Runtime.CompilerServices;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. namespace Compdfkit_Tools.PDFControl
  8. {
  9. public partial class AddCertificationControl : UserControl, INotifyPropertyChanged
  10. {
  11. public Dictionary<bool, CreateCertificationMode> getCreateCertificationMode = new Dictionary<bool, CreateCertificationMode>()
  12. {
  13. {true, CreateCertificationMode.AddExistedCertification},
  14. {false, CreateCertificationMode.AddCustomCertification}
  15. };
  16. private bool _addExistedCertification = true;
  17. public bool AddExistedCertification
  18. {
  19. get => _addExistedCertification;
  20. set => UpdateProper(ref _addExistedCertification, value);
  21. }
  22. private bool _addCustomCertification;
  23. public bool AddCustomCertification
  24. {
  25. get => _addCustomCertification;
  26. set => UpdateProper(ref _addCustomCertification, value);
  27. }
  28. public event EventHandler<CreateCertificationMode> ContinueEvent;
  29. public event EventHandler CancelEvent;
  30. public event PropertyChangedEventHandler PropertyChanged;
  31. public AddCertificationControl()
  32. {
  33. InitializeComponent();
  34. DataContext = this;
  35. }
  36. private void ContinueBtn_Click(object sender, RoutedEventArgs e)
  37. {
  38. ContinueEvent?.Invoke(this, getCreateCertificationMode[AddExistedCertification]);
  39. }
  40. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  41. {
  42. CancelEvent?.Invoke(this, EventArgs.Empty);
  43. }
  44. protected void UpdateProper<T>(ref T properValue,
  45. T newValue,
  46. [CallerMemberName] string properName = "")
  47. {
  48. if (object.Equals(properValue, newValue))
  49. return;
  50. properValue = newValue;
  51. OnPropertyChanged(properName);
  52. }
  53. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  54. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  55. }
  56. }