using ComPDFKitViewer.AnnotEvent; using ComPDFKitViewer.PdfViewer; using PDF_Master.Model; using PDF_Master.Properties; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel { internal class StickyNotePopupViewModel : BindableBase, INavigationAware { private string authorText; public string AuthorText { get { return authorText; } set { SetProperty(ref authorText, value); } } private string dateText; public string DateText { get { return dateText; } set { SetProperty(ref dateText, value); } } private string contentText; public string ContentText { get { return contentText; } set { SetProperty(ref contentText, value); } } private ViewContentViewModel ViewContentViewModel; private StickyAnnotArgs StickyAnnotArgs; private AnnotCommandArgs AnnotCommandArgs; private CPDFViewer PDFViewer; public DelegateCommand ContentTextLostFocus { get; set; } public StickyNotePopupViewModel() { ContentTextLostFocus = new DelegateCommand(ContentText_LostFocus); } private void ContentText_LostFocus(object obj) { if (ViewContentViewModel == null || StickyAnnotArgs == null || PDFViewer == null || AnnotCommandArgs == null) { return; } if (string.IsNullOrEmpty(ContentText)) { ViewContentViewModel.IsNoteAdd = false; return; } StickyAnnotArgs.StickyNote = ContentText; PDFViewer.CreatePageAnnot(AnnotCommandArgs.PageIndex, StickyAnnotArgs); ViewContentViewModel.IsNoteAdd = false; } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { if(StickyAnnotArgs != null && string.IsNullOrEmpty(StickyAnnotArgs.Content)) { PDFViewer.RemovePageAnnot(StickyAnnotArgs.PageIndex, StickyAnnotArgs.AnnotIndex); } } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out ViewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.StickyAnnotArgs, out StickyAnnotArgs); navigationContext.Parameters.TryGetValue(ParameterNames.AnnotCommandArgs, out AnnotCommandArgs); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); SetToolParam(); AuthorText = Settings.Default.AppProperties.Description.Author; DateText = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); } private void SetToolParam() { if(PDFViewer != null && StickyAnnotArgs != null && string.IsNullOrEmpty(StickyAnnotArgs.Content)) { PDFViewer.SetToolParam(StickyAnnotArgs); } } } }