RadioButtonProperty.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using ComPDFKit.PDFAnnotation.Form;
  2. using ComPDFKit.PDFAnnotation;
  3. using Compdfkit_Tools.Common;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. namespace Compdfkit_Tools.PDFControl
  22. {
  23. /// <summary>
  24. /// RadioButtonProperty.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class RadioButtonProperty : UserControl
  27. {
  28. private WidgetRadioButtonArgs widgetArgs = null;
  29. private AnnotAttribEvent annotAttribEvent = null;
  30. private CPDFViewer pdfViewer;
  31. bool IsLoadedData = false;
  32. public RadioButtonProperty()
  33. {
  34. InitializeComponent();
  35. }
  36. #region Loaded
  37. public void SetProperty(WidgetArgs Args, AnnotAttribEvent e, CPDFViewer cPDFViewer)
  38. {
  39. widgetArgs = (WidgetRadioButtonArgs)Args;
  40. annotAttribEvent = e;
  41. pdfViewer = cPDFViewer;
  42. }
  43. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  44. {
  45. FieldNameText.Text = widgetArgs.FieldName;
  46. FormFieldCombox.SelectedIndex = (int)widgetArgs.FormField;
  47. BorderColorPickerControl.SetCheckedForColor(widgetArgs.LineColor);
  48. BackgroundColorPickerControl.SetCheckedForColor(widgetArgs.BgColor);
  49. RadioButtonStyleCombox.SelectedIndex = (int)widgetArgs.CheckStyle;
  50. chkSelected.IsChecked = widgetArgs.IsChecked;
  51. if (IsShowWarning())
  52. {
  53. WarningPanel.Visibility = Visibility.Collapsed;
  54. }
  55. else
  56. {
  57. WarningPanel.Visibility = Visibility.Visible;
  58. }
  59. IsLoadedData = true;
  60. }
  61. private bool IsShowWarning()
  62. {
  63. int count = 0;
  64. var page = pdfViewer.Document.PageAtIndex(pdfViewer.CurrentIndex);
  65. List<CPDFAnnotation> annotList = page.GetAnnotations();
  66. if (annotList != null && annotList.Count > 0)
  67. {
  68. count = annotList.Where(x => x.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  69. .Cast<CPDFWidget>().Where(x => x.WidgeType == C_WIDGET_TYPE.WIDGET_RADIOBUTTON).Count();
  70. }
  71. return count>1;
  72. }
  73. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  74. {
  75. IsLoadedData = false;
  76. }
  77. #endregion
  78. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  79. {
  80. if (IsLoadedData)
  81. {
  82. annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
  83. annotAttribEvent.UpdateAnnot();
  84. }
  85. }
  86. private void FormFieldCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  87. {
  88. if (IsLoadedData)
  89. {
  90. annotAttribEvent.UpdateAttrib(AnnotAttrib.FormField, (sender as ComboBox).SelectedIndex);
  91. annotAttribEvent.UpdateAnnot();
  92. }
  93. }
  94. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  95. {
  96. if (IsLoadedData)
  97. {
  98. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)BorderColorPickerControl.Brush).Color);
  99. annotAttribEvent.UpdateAnnot();
  100. }
  101. }
  102. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  103. {
  104. if (IsLoadedData)
  105. {
  106. annotAttribEvent.UpdateAttrib(AnnotAttrib.FillColor, ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color);
  107. annotAttribEvent.UpdateAnnot();
  108. }
  109. }
  110. private void RadioButtonStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  111. {
  112. if (IsLoadedData)
  113. {
  114. annotAttribEvent.UpdateAttrib(AnnotAttrib.CheckStyle, (sender as ComboBox).SelectedIndex);
  115. annotAttribEvent.UpdateAnnot();
  116. }
  117. }
  118. private void chkSelected_Checked(object sender, RoutedEventArgs e)
  119. {
  120. if (IsLoadedData)
  121. {
  122. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsChecked, true);
  123. annotAttribEvent.UpdateAnnot();
  124. }
  125. }
  126. private void chkSelected_Unchecked(object sender, RoutedEventArgs e)
  127. {
  128. if (IsLoadedData)
  129. {
  130. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsChecked, false);
  131. annotAttribEvent.UpdateAnnot();
  132. }
  133. }
  134. }
  135. }