RadioButtonProperty.xaml.cs 4.6 KB

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