TextEditProperty.xaml.cs 4.0 KB

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