FreetextAnnotProperty.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using PDF_Office.CustomControl;
  2. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  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. namespace PDF_Office.Views.PropertyPanel.AnnotPanel
  19. {
  20. /// <summary>
  21. /// FreetextAnnotProperty.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class FreetextAnnotProperty : UserControl
  24. {
  25. public FreetextAnnotProperty()
  26. {
  27. InitializeComponent();
  28. FontFamilyBox.SelectionChanged += FontFamilyBox_SelectionChanged;
  29. FontStyleBox.SelectionChanged += FontStyleBox_SelectionChanged;
  30. FontSizeBox.SelectionChanged += FontSizeBox_SelectionChanged;
  31. ThicknessBox.SelectionChanged += ThicknessBox_SelectionChanged;
  32. this.Loaded += usercontrol_Loaded;
  33. cusColor.SelectedColorHandler += cusColor_SelectedColorHandler;
  34. layerThick.SelectedValueChanged += layerThick_SelectedValue;
  35. }
  36. private void usercontrol_Loaded(object sender, RoutedEventArgs e)
  37. {
  38. FontFamilyBox.SelectedIndex = 0;
  39. FontStyleBox.SelectedIndex = 0;
  40. FontSizeBox.SelectedIndex = 0;
  41. ThicknessBox.SelectedIndex = 0;
  42. }
  43. private void ThicknessBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  44. {
  45. var listItem = ThicknessBox.ItemContainerGenerator.ContainerFromItem(ThicknessBox.SelectedItem) as ComboBoxItem;
  46. if (listItem != null)
  47. ThicknessText.Text = listItem.Content.ToString();
  48. else
  49. ThicknessText.Text = "1";
  50. }
  51. private void layerThick_SelectedValue(object sender, double e)
  52. {
  53. var data = this.DataContext as FreetextAnnotPropertyViewModel;
  54. if (data != null)
  55. {
  56. data.SelectedFillOpacityCommand?.Execute(e);
  57. }
  58. }
  59. private void FontSizeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  60. {
  61. var listItem = FontSizeBox.ItemContainerGenerator.ContainerFromItem(FontSizeBox.SelectedItem) as ComboBoxItem;
  62. if (listItem != null)
  63. FontSizeText.Text = listItem.Content.ToString();
  64. else
  65. FontSizeText.Text = "6";
  66. }
  67. private void FontStyleBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  68. {
  69. var listItem = FontStyleBox.ItemContainerGenerator.ContainerFromItem(FontStyleBox.SelectedItem) as ComboBoxItem;
  70. if (listItem != null)
  71. FontStyleText.Text = listItem.Content.ToString();
  72. else
  73. FontStyleText.Text = "Regular";
  74. }
  75. private void FontFamilyBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  76. {
  77. var listItem = FontFamilyBox.ItemContainerGenerator.ContainerFromItem(FontFamilyBox.SelectedItem) as ComboBoxItem;
  78. if (listItem != null)
  79. FontFamilyText.Text = (listItem.Content as TextBlock).Text;
  80. else
  81. FontFamilyText.Text = "Courier New";
  82. }
  83. private void BtnTextAlign_Click(object sender, RoutedEventArgs e)
  84. {
  85. var btn = sender as ToggleButton;
  86. foreach(var item in ToolGrid.Children)
  87. {
  88. var btnItem = item as ToggleButton;
  89. if(btnItem != null)
  90. {
  91. if(btn!= btnItem)
  92. btnItem.IsChecked = false;
  93. else
  94. btnItem.IsChecked = true;
  95. }
  96. }
  97. }
  98. private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
  99. {
  100. var btn = sender as CustomIconToggleBtn;
  101. foreach (var item in PnlLineStyle.Children)
  102. {
  103. var btnItem = item as CustomIconToggleBtn;
  104. if (btnItem != null)
  105. {
  106. if (btn != btnItem)
  107. btnItem.IsChecked = false;
  108. else
  109. btnItem.IsChecked = true;
  110. }
  111. }
  112. }
  113. private void FontColorBox_SelectedColorChanged(object sender, Color? e)
  114. {
  115. var data = this.DataContext as FreetextAnnotPropertyViewModel;
  116. data.SelectedColorCommand?.Execute(e);
  117. }
  118. private void cusColor_SelectedColorHandler(object sender, Color e)
  119. {
  120. var data = this.DataContext as FreetextAnnotPropertyViewModel;
  121. data.SelectedFillColorCommand?.Execute(e);
  122. }
  123. }
  124. }