ConfidenceControl.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using Compdfkit_Tools.DigitalSignature.CPDFSignatureListControl;
  19. using Compdfkit_Tools.Properties;
  20. using ComPDFKit.DigitalSign;
  21. namespace Compdfkit_Tools.PDFControl
  22. {
  23. /// <summary>
  24. /// ConfidenceControl.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class ConfidenceControl : UserControl, INotifyPropertyChanged
  27. {
  28. public static ResourceDictionary ResourceDictionary { get; set; }
  29. private bool isTrusted;
  30. private CPDFSignatureCertificate cpdfCertificate;
  31. public bool IsTrusted
  32. {
  33. get => isTrusted;
  34. set => UpdateProper(ref isTrusted, value);
  35. }
  36. public ConfidenceControl()
  37. {
  38. InitializeComponent();
  39. DataContext = this;
  40. ResourceDictionary = this.Resources;
  41. }
  42. public void LoadConfidenceInfo(CPDFSignatureCertificate certificate)
  43. {
  44. cpdfCertificate = certificate;
  45. VerifyCertificate();
  46. }
  47. public void VerifyCertificate()
  48. {
  49. if (cpdfCertificate != null)
  50. {
  51. cpdfCertificate.CheckCertificateIsTrusted();
  52. IsTrusted = cpdfCertificate.IsTrusted;
  53. }
  54. }
  55. public event PropertyChangedEventHandler PropertyChanged;
  56. protected void UpdateProper<T>(ref T properValue,
  57. T newValue,
  58. [CallerMemberName] string properName = "")
  59. {
  60. if (object.Equals(properValue, newValue))
  61. return;
  62. properValue = newValue;
  63. OnPropertyChanged(properName);
  64. }
  65. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  66. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  67. private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  68. {
  69. cpdfCertificate.AddToTrustedCertificates();
  70. VerifyCertificate();
  71. }
  72. }
  73. public class ConfidenceStatusToPathConverter : IValueConverter
  74. {
  75. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  76. {
  77. ResourceDictionary resourceDictionary = ConfidenceControl.ResourceDictionary;
  78. if (value is bool isTrusted)
  79. {
  80. if (isTrusted)
  81. {
  82. return resourceDictionary["ValidPath"];
  83. }
  84. else
  85. {
  86. return resourceDictionary["InvalidPath"];
  87. }
  88. }
  89. return null;
  90. }
  91. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  92. {
  93. return null;
  94. }
  95. }
  96. }