using ComPDFKitViewer; using PDF_Office.CustomControl.CompositeControl; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; 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 PDF_Office.Views.PropertyPanel.AnnotPanel { /// /// StickyNotePopup.xaml 的交互逻辑 /// public partial class StickyNotePopup : StickyPopupExt { private ObservableCollection colors = new ObservableCollection(); private Point PressPoint; public Point OffsetParent; private byte saveOpacity = 1; public bool CanMove { get; set; } = true; public StickyNotePopup() { InitializeComponent(); AddHandler(MouseUpEvent, new MouseButtonEventHandler(StickyPopupControl_MouseUp), true); ContentText.AddHandler(MouseDownEvent, new MouseButtonEventHandler(StickyPopupControl_MouseDown), true); Loaded += StickyPopupControl_Loaded; Unloaded += StickyPopupControl_Unloaded; ContentText.GotFocus += ContentText_GotFocus; ContentText.LostFocus += ContentText_LostFocus; colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10))); colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0x10, 0x10))); colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10))); colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF))); ListColor.ItemsSource = colors; } private void ContentText_LostFocus(object sender, RoutedEventArgs e) { e.Handled = true; Color bkColor = (border.BorderBrush as SolidColorBrush).Color; bkColor.A = saveOpacity; border.BorderBrush = new SolidColorBrush(bkColor); CloseText_MouseUp(this, null); border.BorderBrush = this.Background; this.Background = new SolidColorBrush(Colors.Transparent); AuthorText.Text = this.Author; DateTextui.Text = this.DateText; } private void ContentText_GotFocus(object sender, RoutedEventArgs e) { Color bkColor = (border.BorderBrush as SolidColorBrush).Color; saveOpacity = bkColor.A; bkColor.A = 255; border.BorderBrush = new SolidColorBrush(bkColor); border.BorderBrush = this.Background; this.Background = new SolidColorBrush(Colors.Transparent); AuthorText.Text = this.Author; DateTextui.Text = this.DateText; } private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e) { ContentText.Focus(); ContentText.CaretIndex = ContentText.Text.Length; ContentText.Text = this.StickyNote; } private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e) { PressPoint = new Point(0, 0); } private void StickyPopupControl_MouseUp(object sender, MouseButtonEventArgs e) { CanMove = true; } public string StickyText { get { return ContentText.Text; } set { ContentText.Text = value; } } public string StickyAuthor { get { return AuthorText.Text; } set { AuthorText.Text = value; } } public string StickyDate { get { return DateTextui.Text; } set { DateTextui.Text = value; } } private void CloseText_MouseUp(object sender, MouseButtonEventArgs e) { if (e != null) { e.Handled = true; } PlaceChange = null; RemoveFromLayer(); if (Closed != null) { Closed.Invoke(sender, EventArgs.Empty); } } private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { var color = ListColor.SelectedItem as ColorItem; if(color != null) { this.SetStickyColor((color.Color as SolidColorBrush).Color); } } private void StickyPopupControl_Unloaded(object sender, RoutedEventArgs e) { if (StickyNote != ContentText.Text) this.SetStickyNote(ContentText.Text); } } }