123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using compdfkit_tools.Common;
- using compdfkit_tools.Data;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Security.AccessControl;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.Form.Property
- {
- /// <summary>
- /// TextFieldProperty.xaml 的交互逻辑
- /// </summary>
- public partial class TextFieldProperty : UserControl, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public void RaisePropertyChanged(string PropertyName)
- {
- if (this.PropertyChanged != null)
- {
- this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
- }
- }
- private WidgetTextBoxArgs widgetArgs = null;
- private AnnotAttribEvent annotAttribEvent = null;
- public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
- {
- 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
- };
- bool IsLoadedData = false;
- public TextFieldProperty()
- {
- InitializeComponent();
- }
- #region Loaded
- public void SetProperty(WidgetArgs Args, AnnotAttribEvent e)
- {
- widgetArgs = (WidgetTextBoxArgs)Args;
- annotAttribEvent = e;
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- Binding SizeListbinding = new Binding();
- SizeListbinding.Source = this;
- SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
- FontSizeCombox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
- FieldNameText.Text = widgetArgs.FieldName;
- FormFieldCombox.SelectedIndex = (int)widgetArgs.FormField;
- SetColor(BorderColorPickerControl, widgetArgs.LineColor);
- SetColor(BackgroundColorPickerControl, widgetArgs.BgColor);
- SetColor(TextColorPickerControl, widgetArgs.FontColor);
- SetFontName(widgetArgs.FontName);
- SetFontStyle(widgetArgs.IsItalic, widgetArgs.IsBold);
- SetFontSize(widgetArgs.FontSize);
- TextAlignmentCombox.SelectedIndex = (int)widgetArgs.Alignment;
- DefaultText.Text = widgetArgs.Text;
- chkMutiline.IsChecked = widgetArgs.IsMultiLine;
- IsLoadedData = true;
- }
- private void SetFontSize(double size)
- {
- int index = SizeList.IndexOf((int)size);
- FontSizeCombox.SelectedIndex = index;
- }
- private void SetFontStyle(bool IsItalic, bool IsBold)
- {
- int index = 0;
- if (IsItalic && IsBold)
- {
- index = 3;
- }
- else if (IsItalic)
- {
- index = 2;
- }
- else if (IsBold)
- {
- index = 1;
- }
- FontStyleCombox.SelectedIndex = index;
- }
- private void SetFontName(string fontName)
- {
- int index = -1;
- switch (fontName)
- {
- case "Arial":
- index = 0; break;
- case "Helvetica":
- index = 0; break;
- case "Courier New":
- index = 1; break;
- case "Times New Roman":
- index = 2; break;
- default:
- break;
- }
- FontCombox.SelectedIndex = index;
- }
- private void SetColor(ColorPickerControl Control, Color color)
- {
- List<SolidColorBrush> brushes = Control.GetButtonColor();
- int index = brushes.IndexOf(new SolidColorBrush(color));
- if (index < 0)
- {
- Control.SetIsChecked(4);
- Control.Brush = new SolidColorBrush(color);
- }
- else
- {
- Control.SetIsChecked(index);
- }
- }
- #endregion
- private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
- annotAttribEvent.UpdateAnnot();
- }
- }
- private void UserControl_Unloaded(object sender, RoutedEventArgs e)
- {
- IsLoadedData = false;
- }
- }
- }
|