TextFieldProperty.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using compdfkit_tools.Common;
  2. using compdfkit_tools.Data;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.Linq;
  10. using System.Security.AccessControl;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace compdfkit_tools.Form.Property
  23. {
  24. /// <summary>
  25. /// TextFieldProperty.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class TextFieldProperty : UserControl, INotifyPropertyChanged
  28. {
  29. public event PropertyChangedEventHandler PropertyChanged;
  30. public void RaisePropertyChanged(string PropertyName)
  31. {
  32. if (this.PropertyChanged != null)
  33. {
  34. this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
  35. }
  36. }
  37. private WidgetTextBoxArgs widgetArgs = null;
  38. private AnnotAttribEvent annotAttribEvent = null;
  39. public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
  40. {
  41. 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
  42. };
  43. bool IsLoadedData = false;
  44. public TextFieldProperty()
  45. {
  46. InitializeComponent();
  47. }
  48. #region Loaded
  49. public void SetProperty(WidgetArgs Args, AnnotAttribEvent e)
  50. {
  51. widgetArgs = (WidgetTextBoxArgs)Args;
  52. annotAttribEvent = e;
  53. }
  54. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  55. {
  56. Binding SizeListbinding = new Binding();
  57. SizeListbinding.Source = this;
  58. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  59. FontSizeCombox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  60. FieldNameText.Text = widgetArgs.FieldName;
  61. FormFieldCombox.SelectedIndex = (int)widgetArgs.FormField;
  62. SetColor(BorderColorPickerControl, widgetArgs.LineColor);
  63. SetColor(BackgroundColorPickerControl, widgetArgs.BgColor);
  64. SetColor(TextColorPickerControl, widgetArgs.FontColor);
  65. SetFontName(widgetArgs.FontName);
  66. SetFontStyle(widgetArgs.IsItalic, widgetArgs.IsBold);
  67. SetFontSize(widgetArgs.FontSize);
  68. TextAlignmentCombox.SelectedIndex = (int)widgetArgs.Alignment;
  69. DefaultText.Text = widgetArgs.Text;
  70. chkMutiline.IsChecked = widgetArgs.IsMultiLine;
  71. IsLoadedData = true;
  72. }
  73. private void SetFontSize(double size)
  74. {
  75. int index = SizeList.IndexOf((int)size);
  76. FontSizeCombox.SelectedIndex = index;
  77. }
  78. private void SetFontStyle(bool IsItalic, bool IsBold)
  79. {
  80. int index = 0;
  81. if (IsItalic && IsBold)
  82. {
  83. index = 3;
  84. }
  85. else if (IsItalic)
  86. {
  87. index = 2;
  88. }
  89. else if (IsBold)
  90. {
  91. index = 1;
  92. }
  93. FontStyleCombox.SelectedIndex = index;
  94. }
  95. private void SetFontName(string fontName)
  96. {
  97. int index = -1;
  98. switch (fontName)
  99. {
  100. case "Arial":
  101. index = 0; break;
  102. case "Helvetica":
  103. index = 0; break;
  104. case "Courier New":
  105. index = 1; break;
  106. case "Times New Roman":
  107. index = 2; break;
  108. default:
  109. break;
  110. }
  111. FontCombox.SelectedIndex = index;
  112. }
  113. private void SetColor(ColorPickerControl Control, Color color)
  114. {
  115. List<SolidColorBrush> brushes = Control.GetButtonColor();
  116. int index = brushes.IndexOf(new SolidColorBrush(color));
  117. if (index < 0)
  118. {
  119. Control.SetIsChecked(4);
  120. Control.Brush = new SolidColorBrush(color);
  121. }
  122. else
  123. {
  124. Control.SetIsChecked(index);
  125. }
  126. }
  127. #endregion
  128. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  129. {
  130. if (IsLoadedData)
  131. {
  132. annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
  133. annotAttribEvent.UpdateAnnot();
  134. }
  135. }
  136. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  137. {
  138. IsLoadedData = false;
  139. }
  140. }
  141. }