StickyNotePopup.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using ComPDFKitViewer;
  2. using PDF_Office.CustomControl.CompositeControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  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. /// StickyNotePopup.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class StickyNotePopup : StickyPopupExt
  24. {
  25. private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
  26. private Point PressPoint;
  27. public Point OffsetParent;
  28. private byte saveOpacity = 1;
  29. public bool CanMove { get; set; } = true;
  30. public StickyNotePopup()
  31. {
  32. InitializeComponent();
  33. AddHandler(MouseUpEvent, new MouseButtonEventHandler(StickyPopupControl_MouseUp), true);
  34. ContentText.AddHandler(MouseDownEvent, new MouseButtonEventHandler(StickyPopupControl_MouseDown), true);
  35. Loaded += StickyPopupControl_Loaded;
  36. Unloaded += StickyPopupControl_Unloaded;
  37. ContentText.GotFocus += ContentText_GotFocus;
  38. ContentText.LostFocus += ContentText_LostFocus;
  39. colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10)));
  40. colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0x10, 0x10)));
  41. colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
  42. colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF)));
  43. ListColor.ItemsSource = colors;
  44. }
  45. private void ContentText_LostFocus(object sender, RoutedEventArgs e)
  46. {
  47. e.Handled = true;
  48. Color bkColor = (border.BorderBrush as SolidColorBrush).Color;
  49. bkColor.A = saveOpacity;
  50. border.BorderBrush = new SolidColorBrush(bkColor);
  51. CloseText_MouseUp(this, null);
  52. border.BorderBrush = this.Background;
  53. this.Background = new SolidColorBrush(Colors.Transparent);
  54. AuthorText.Text = this.Author;
  55. DateTextui.Text = this.DateText;
  56. }
  57. private void ContentText_GotFocus(object sender, RoutedEventArgs e)
  58. {
  59. Color bkColor = (border.BorderBrush as SolidColorBrush).Color;
  60. saveOpacity = bkColor.A;
  61. bkColor.A = 255;
  62. border.BorderBrush = new SolidColorBrush(bkColor);
  63. border.BorderBrush = this.Background;
  64. this.Background = new SolidColorBrush(Colors.Transparent);
  65. AuthorText.Text = this.Author;
  66. DateTextui.Text = this.DateText;
  67. }
  68. private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e)
  69. {
  70. ContentText.Focus();
  71. ContentText.CaretIndex = ContentText.Text.Length;
  72. ContentText.Text = this.StickyNote;
  73. }
  74. private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e)
  75. {
  76. PressPoint = new Point(0, 0);
  77. }
  78. private void StickyPopupControl_MouseUp(object sender, MouseButtonEventArgs e)
  79. {
  80. CanMove = true;
  81. }
  82. public string StickyText
  83. {
  84. get
  85. {
  86. return ContentText.Text;
  87. }
  88. set
  89. {
  90. ContentText.Text = value;
  91. }
  92. }
  93. public string StickyAuthor
  94. {
  95. get
  96. {
  97. return AuthorText.Text;
  98. }
  99. set
  100. {
  101. AuthorText.Text = value;
  102. }
  103. }
  104. public string StickyDate
  105. {
  106. get
  107. {
  108. return DateTextui.Text;
  109. }
  110. set
  111. {
  112. DateTextui.Text = value;
  113. }
  114. }
  115. private void CloseText_MouseUp(object sender, MouseButtonEventArgs e)
  116. {
  117. if (e != null)
  118. {
  119. e.Handled = true;
  120. }
  121. PlaceChange = null;
  122. RemoveFromLayer();
  123. if (Closed != null)
  124. {
  125. Closed.Invoke(sender, EventArgs.Empty);
  126. }
  127. }
  128. private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
  129. {
  130. var color = ListColor.SelectedItem as ColorItem;
  131. if(color != null)
  132. {
  133. this.SetStickyColor((color.Color as SolidColorBrush).Color);
  134. }
  135. }
  136. private void StickyPopupControl_Unloaded(object sender, RoutedEventArgs e)
  137. {
  138. if (StickyNote != ContentText.Text)
  139. this.SetStickyNote(ContentText.Text);
  140. }
  141. }
  142. }