using ComPDFKit.PDFAnnotation; using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using DryIoc; using Microsoft.Office.Interop.Word; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Model.BOTA; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Annotations; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; namespace PDF_Master.ViewModels.Dialog.BOTA { public class AddAnnotationDialogViewModel : BindableBase, IDialogAware { private string title = ""; public string Title { get { return title; } set { SetProperty(ref title, value); } } public event Action RequestClose; //private string markupContent; //public string MarkupContent //{ // get { return markupContent; } // set // { // SetProperty(ref markupContent, value); // } //} private string contentText; public string ContentText { get { return contentText; } set { SetProperty(ref contentText, value); } } private string annotationName; public string AnnotationName { get { return annotationName; } set { SetProperty(ref annotationName, value); } } private Visibility tipVisibility = Visibility.Collapsed; public Visibility TipVisibility { get { return tipVisibility; } set { SetProperty(ref tipVisibility, value); } } public AnnotationHandlerEventArgs Annotation { get; set; } public AnnotAttribEvent AnnotEvent { get; set; } public DelegateCommand CreateCommnad { get; set; } public DelegateCommand CancelCommand { get; set; } public DelegateCommand LostFocusCommand { get; set; } public DelegateCommand KeyDownCommand { get; set; } public AddAnnotationDialogViewModel() { CancelCommand = new DelegateCommand(CancelEvent); CreateCommnad = new DelegateCommand(CreateEvent); LostFocusCommand = new DelegateCommand(LostFocusEvent); KeyDownCommand = new DelegateCommand(KeyDown); } private void KeyDown(object obj) { if (obj is CompositeCommandParameter composite) { if (composite.EventArgs is System.Windows.Input.KeyEventArgs eventArgs) { if (eventArgs.Key == Key.Enter) { LostFocusEvent(obj); } } } } private void LostFocusEvent(object obj) { if (obj is CompositeCommandParameter composite) { if (composite.Parameter is TextBox textBox) { Annotation.Content = textBox.Text; AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, textBox.Text); AnnotEvent?.UpdateAnnot(); } } } private void CreateEvent() { DialogParameters valuePairs = new DialogParameters(); valuePairs.Add(ParameterNames.Annotation, Annotation); valuePairs.Add(ParameterNames.AnnotEvent, AnnotEvent); RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs)); } private void CancelEvent() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { AnnotationHandlerEventArgs annotation; parameters.TryGetValue(ParameterNames.Annotation, out annotation); if (annotation != null) { Annotation = annotation; Dictionary annotAttribsList = annotation.AnnotHandlerEventArgs.GetAnnotAttrib(); AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotation.AnnotHandlerEventArgs, annotAttribsList); ContentText = annotation.Content; AnnotationName = "页面" + (annotation.PageIndex + 1).ToString(); if (string.IsNullOrEmpty(ContentText)) { TipVisibility = Visibility.Visible; } else { TipVisibility = Visibility.Collapsed; } return; } } } }