TextEditProperty.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using PDF_Office.ViewModels.PropertyPanel;
  2. using PDF_Office.ViewModels.PropertyPanel.PDFEdit;
  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.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace PDF_Office.Views.PropertyPanel.PDFEdit
  18. {
  19. /// <summary>
  20. /// TextEditProperty.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class TextEditProperty : UserControl
  23. {
  24. public TextEditPropertyViewModel ViewModel => DataContext as TextEditPropertyViewModel;
  25. public TextEditProperty()
  26. {
  27. InitializeComponent();
  28. }
  29. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  30. {
  31. InitEventHandler();
  32. InitVariable();
  33. }
  34. private void InitEventHandler()
  35. {
  36. FontFamilyBox.SelectionChanged -= FontFamilyBox_SelectionChanged;
  37. FontStyleBox.SelectionChanged -= FontStyleBox_SelectionChanged;
  38. FontSizeBox.SelectionChanged -= FontSizeBox_SelectionChanged;
  39. FontColorBox.SelectedColorHandler -= FontColorBox_SelectedColorHandler;
  40. FontFamilyBox.SelectionChanged += FontFamilyBox_SelectionChanged;
  41. FontStyleBox.SelectionChanged += FontStyleBox_SelectionChanged;
  42. FontSizeBox.SelectionChanged += FontSizeBox_SelectionChanged;
  43. FontColorBox.SelectedColorHandler += FontColorBox_SelectedColorHandler;
  44. if(ViewModel != null)
  45. {
  46. ViewModel.ClearCheckedAglin -= ViewModel_ClearCheckedAglin;
  47. ViewModel.ClearCheckedAglin += ViewModel_ClearCheckedAglin;
  48. }
  49. }
  50. private void InitVariable()
  51. {
  52. FontTitleBox.SelectedIndex = 0;
  53. FontFamilyBox.SelectedIndex = 0;
  54. FontStyleBox.SelectedIndex = 0;
  55. FontSizeBox.SelectedIndex = 0;
  56. }
  57. private void ViewModel_ClearCheckedAglin(object sender, EventArgs e)
  58. {
  59. foreach (var item in LayoutAlignGrid.Children)
  60. {
  61. var radioBtn = item as RadioButton;
  62. if (radioBtn != null)
  63. {
  64. radioBtn.IsChecked = false;
  65. }
  66. }
  67. }
  68. private void FontSizeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  69. {
  70. var listItem = FontSizeBox.ItemContainerGenerator.ContainerFromItem(FontSizeBox.SelectedItem) as ComboBoxItem;
  71. if (listItem != null)
  72. FontSizeText.Text = listItem.Content.ToString();
  73. else
  74. FontSizeText.Text = "6";
  75. }
  76. private void FontStyleBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  77. {
  78. var listItem = FontStyleBox.ItemContainerGenerator.ContainerFromItem(FontStyleBox.SelectedItem) as ComboBoxItem;
  79. if (listItem != null)
  80. FontStyleText.Text = listItem.Content.ToString();
  81. else
  82. FontStyleText.Text = "Regular";
  83. }
  84. private void FontFamilyBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  85. {
  86. var listItem = FontFamilyBox.ItemContainerGenerator.ContainerFromItem(FontFamilyBox.SelectedItem) as ComboBoxItem;
  87. if (listItem != null)
  88. FontFamilyText.Text = (listItem.Content as TextBlock).Text;
  89. else
  90. FontFamilyText.Text = "Courier New";
  91. }
  92. private void FontColorBox_SelectedColorHandler(object sender, Color e)
  93. {
  94. var data = this.DataContext as TextEditPropertyViewModel;
  95. if (data != null)
  96. {
  97. data.SelectedColorCommand?.Execute(e);
  98. }
  99. }
  100. private void BtnTextAlign_Click(object sender, RoutedEventArgs e)
  101. {
  102. }
  103. }
  104. }