123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- 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<IDialogResult> 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 placeHolderText;
- public string PlaceHolderText
- {
- get { return placeHolderText; }
- set
- {
- SetProperty(ref placeHolderText, value);
- }
- }
- private string btnOKContent;
- public string BtnOKContent
- {
- get { return btnOKContent; }
- set
- {
- SetProperty(ref btnOKContent, value);
- }
- }
- private string btnCancelContent;
- public string BtnCancelContent
- {
- get { return btnCancelContent; }
- set
- {
- SetProperty(ref btnCancelContent, 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<object> LostFocusCommand { get; set; }
- public DelegateCommand<object> KeyDownCommand { get; set; }
- public AddAnnotationDialogViewModel()
- {
- CancelCommand = new DelegateCommand(CancelEvent);
- CreateCommnad = new DelegateCommand(CreateEvent);
- LostFocusCommand = new DelegateCommand<object>(LostFocusEvent);
- KeyDownCommand = new DelegateCommand<object>(KeyDown);
- SetLange();
- }
- private void SetLange()
- {
- PlaceHolderText = App.MainPageLoader.GetString("PlaceText_AddNote");
- BtnOKContent = App.ServiceLoader.GetString("Text_ok");
- BtnCancelContent = App.ServiceLoader.GetString("Text_cancel");
- }
- 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.MarkupContent = 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<AnnotationHandlerEventArgs>(ParameterNames.Annotation, out annotation);
- if (annotation != null)
- {
- Annotation = annotation;
- Dictionary<AnnotAttrib, object> annotAttribsList = annotation.AnnotHandlerEventArgs.GetAnnotAttrib();
- AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotation.AnnotHandlerEventArgs, annotAttribsList);
- ContentText = annotation.Content;
- AnnotationName = "Page" + (annotation.PageIndex + 1).ToString();
- if (string.IsNullOrEmpty(ContentText))
- {
- TipVisibility = Visibility.Visible;
- }
- else
- {
- TipVisibility = Visibility.Collapsed;
- }
- return;
- }
- }
- }
- }
|