using ComPDFKit.PDFAnnotation; using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using ComPDFKitViewer.PdfViewer; using Microsoft.Office.Interop.Word; using Microsoft.Win32; using PDF_Office.CustomControl; using PDF_Office.EventAggregators; using PDF_Office.Helper; using PDF_Office.Model; using PDF_Office.Properties; using PDF_Office.ViewModels.BOTA; using PDF_Office.ViewModels.PropertyPanel; using PDF_Office.ViewModels.PropertyPanel.AnnotPanel; using PDF_Office.Views.BOTA; using PDF_Office.Views.PropertyPanel.AnnotPanel; using PDFSettings; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; namespace PDF_Office.ViewModels.Tools { public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware { private IEventAggregator events; private bool btnSelecttoolIsChecked = false; public bool BtnSelecttoolIsChecked { get { return btnSelecttoolIsChecked; } set { SetProperty(ref btnSelecttoolIsChecked, value); } } private bool btnLinkIsChecked = false; public bool BtnLinkIsChecked { get { return btnLinkIsChecked; } set { SetProperty(ref btnLinkIsChecked, value); } } private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel(); public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; } public DelegateCommand SetAddAnnotationCommand { get; set; } public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) { region = regionManager; events = eventAggregator; MyToolsCommand = new DelegateCommand(BtnMyTools_Click); SetAddAnnotationCommand = new DelegateCommand(AddAnnotation_Click); PropertyRegionName = Guid.NewGuid().ToString(); BindingEvent(); InitDefaultValue(); } private Dictionary ToolExpandDict = new Dictionary(); public void BtnMyTools_Click(CustomIconToggleBtn annotBtn) { //不创建注释,属于注释模板 bool isTemplateAnnot = false; bool isSnapshotEdit = false; AnnotHandlerEventArgs annotArgs = null; if (annotBtn.IsChecked == true) { switch (annotBtn.Tag.ToString()) { case "SnapshotEdit": annotArgs = GetSnapshotEdit(annotBtn); isSnapshotEdit = true; break; case "HighLight": annotArgs = GetHighLight(); break; case "UnderLine": annotArgs = GetUnderLine(); break; case "Squiggly": annotArgs = GetSquiggly(); break; case "Strikeout": annotArgs = GetStrikeout(); break; case "Freehand": annotArgs = GetFreehand(); break; case "Freetext": annotArgs = GetFreetext(); break; case "StickyNote": annotArgs = GetStickyNote(); break; case "Rect": annotArgs = GetRect(); break; case "Circle": annotArgs = GetCircle(); break; case "Arrow": case "Line": annotArgs = GetArrowLine(annotBtn.Tag.ToString()); break; case "Stamp": annotArgs = GetStamp(); isTemplateAnnot = true; break; case "Image": annotArgs = GetImage(annotBtn); break; case "Signature": annotArgs = GetSignature(); isTemplateAnnot = true; break; case "Link": viewContentViewModel.IsCreateLink = false; annotArgs = GetLink(); break; } if (annotArgs != null) { annotArgs.Author = Settings.Default.AppProperties.Description.Author; PDFViewer.SetMouseMode(MouseModes.AnnotCreate); PDFViewer.SetToolParam(annotArgs); } } //当不是注释模板,且无创建注释时,属性面板显示为空内容 if (isTemplateAnnot == false && annotArgs == null) { PDFViewer.SetMouseMode(MouseModes.PanTool); viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); } if (isSnapshotEdit == true) { ShowPropertyPanel(false); isSnapshotEdit = false; } else { ShowPropertyPanel((bool)annotBtn.IsChecked); } } private void AnnotProperty_DefaultStored(object sender, object e) { } private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary e) { if (e != null) { AnnotHandlerEventArgs annotArgs = null; foreach (AnnotArgsType argsType in e.Keys) { switch (argsType) { case AnnotArgsType.AnnotSquare: annotArgs = GetRect(); break; case AnnotArgsType.AnnotCircle: annotArgs = GetCircle(); break; case AnnotArgsType.AnnotLine: var LineTag = e[argsType] as string; annotArgs = GetArrowLine(LineTag); break; } if (annotArgs != null) { annotArgs.Author = Settings.Default.AppProperties.Description.Author; PDFViewer.SetMouseMode(MouseModes.AnnotCreate); PDFViewer.SetToolParam(annotArgs); } ShowPropertyPanel(); } } } private void AnnotPropertyPanel_DataChanged(object sender, Dictionary e) { if (e != null) { foreach (AnnotArgsType argsType in e.Keys) { switch (argsType) { case AnnotArgsType.AnnotHighlight: if (e[argsType] is Color) { HighLightColor = new SolidColorBrush((Color)e[argsType]); } if (e[argsType] is double) { HighLightOpacity = (double)e[argsType]; } break; case AnnotArgsType.AnnotUnderline: if (e[argsType] is Color) { UnderLineColor = new SolidColorBrush((Color)e[argsType]); } if (e[argsType] is double) { underLineOpacity = (double)e[argsType]; } break; case AnnotArgsType.AnnotSquiggly: if (e[argsType] is Color) { SquigglyColor = new SolidColorBrush((Color)e[argsType]); } if (e[argsType] is double) { SquigglyOpacity = (double)e[argsType]; } break; case AnnotArgsType.AnnotStrikeout: if (e[argsType] is Color) { StrikeoutColor = new SolidColorBrush((Color)e[argsType]); } if (e[argsType] is double) { StrikeoutOpacity = (double)e[argsType]; } break; case AnnotArgsType.AnnotFreehand: if (e[argsType] is Color) { // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]); } if (e[argsType] is double) { // FreehandPath.Opacity = (double)e[argsType]; } break; case AnnotArgsType.AnnotErase: if (e[argsType] is ToggleButton) { ToggleButton clickBtn = e[argsType] as ToggleButton; //PDFViewerCtrl viewCtrl = GetCurrentViewer(); // ClearSelectedToolPanel(BtnFreeHand); // if (viewCtrl != null && viewCtrl.PdfViewer != null) { if (clickBtn.IsChecked == true) { if (clickBtn.Tag.ToString() == "PenBtn") { CustomIconToggleBtn btn = new CustomIconToggleBtn(); btn.Tag = "Freehand"; btn.IsChecked = true; BtnMyTools_Click(btn); break; } EraseArgs eraseArgs = new EraseArgs(); eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00); eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00); eraseArgs.Thickness = 10; DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase); if (annotProperty != null) { eraseArgs.Thickness = annotProperty.Thickness; } PDFViewer.ClearSelectAnnots(false); PDFViewer.SetMouseMode(MouseModes.AnnotCreate); PDFViewer.SetToolParam(eraseArgs); Dictionary annotAttribsList = new Dictionary(); annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor; annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor; annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness; AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgs, annotAttribsList); //清空选中注释 //viewCtrl.PdfViewer.ClearSelectAnnots(false); //viewCtrl.PdfViewer.SetMouseMode(MouseModes.AnnotCreate); //viewCtrl.PdfViewer.SetToolParam(eraseArgs); //if (viewCtrl.PropPanel.Children.Count > 0) //{ // FreehandAnnotProperty freehandPropPanel = viewCtrl.PropPanel.Children[0] as FreehandAnnotProperty; // if (freehandPropPanel == null) // { // viewCtrl.PropPanel.Children.Clear(); // freehandPropPanel = new FreehandAnnotProperty(); // freehandPropPanel.EraseSet = true; // freehandPropPanel.SetInkThickness(eraseArgs.Thickness); // freehandPropPanel.DataChanged += AnnotPropertyPanel_DataChanged; // viewCtrl.PropPanel.Children.Add(freehandPropPanel); // } // Dictionary annotAttribsList = new Dictionary(); // annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor; // annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor; // annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness; // freehandPropPanel.AnnotEvent = null; // freehandPropPanel.SetEraseMode(true); // freehandPropPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(eraseArgs, annotAttribsList); //} //else //{ // FreehandAnnotProperty freehandProperty = new FreehandAnnotProperty(); // freehandProperty.DataChanged += AnnotPropertyPanel_DataChanged; // Dictionary annotAttribsList = new Dictionary(); // annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor; // annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor; // annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness; // freehandProperty.SetInkThickness(eraseArgs.Thickness); // freehandProperty.EraseSet = true; // freehandProperty.SetEraseMode(true); // freehandProperty.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(eraseArgs, annotAttribsList); // viewCtrl.AddAnnotPropertyPanel(freehandProperty); //} } else { // BtnFreeHand.IsChecked = true; // BtnTool_Click(BtnFreeHand, new RoutedEventArgs()); } } } break; } } } } public IRegionManager region; public string PropertyRegionName { get; set; } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); // navigationContext.Parameters.TryGetValue(ParameterNames.PropertyPanelContentViewModel, out propertyPanelContentViewModel); if (PDFViewer != null) { PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler; PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler; PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler; PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler; PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler; PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler; PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander; PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander; PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler; PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler; } } private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e) { SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs; SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs; SnapshotEditMenuViewModel.PDFViewer = PDFViewer; SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent; ; var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu; if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0) { e.PopupMenu = popMenu; e.Handle = true; if (popMenu != null && popMenu.Items.Count == 5) { //复制 MenuItem menuItem = popMenu.Items[0] as MenuItem; menuItem.CommandTarget = PDFViewer; menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand; //导出 menuItem = popMenu.Items[1] as MenuItem; menuItem.CommandTarget = PDFViewer; if (menuItem.Items.Count == 3) { MenuItem menuItem1 = menuItem.Items[0] as MenuItem; menuItem1.CommandTarget = PDFViewer; menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand; menuItem1 = menuItem.Items[1] as MenuItem; menuItem1.CommandTarget = PDFViewer; menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand; menuItem1 = menuItem.Items[2] as MenuItem; menuItem1.CommandTarget = PDFViewer; menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand; } //裁剪 menuItem = popMenu.Items[2] as MenuItem; menuItem.CommandTarget = PDFViewer; menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand; //缩放至所选区域 menuItem = popMenu.Items[3] as MenuItem; menuItem.CommandTarget = PDFViewer; menuItem.Visibility = Visibility.Collapsed; //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand; //打印 menuItem = popMenu.Items[4] as MenuItem; menuItem.CommandTarget = PDFViewer; menuItem.Command = SnapshotEditMenuViewModel.PrintCommand; } } } private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair e) { switch (e.Key) { case "CloseSnap": { #region to do //var item = PDFViewerTab.SelectedItem as TabItem; //if (item == null) //{ // ClearSelectedToolPanel(); // return; //} //Grid grid = item.Content as Grid; //if (grid == null || grid.Children.Count == 0) //{ // ClearSelectedToolPanel(); // return; //} //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl; //if (pdfViewer == null) //{ // ClearSelectedToolPanel(); // return; //} #endregion to do switch (PDFViewer.MouseMode) { case MouseModes.SelectTextTool: break; default: BtnSelecttoolIsChecked = false; break; } } break; default: break; } } private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e) { } private void PDFViewer_AnnotEditHandler(object sender, List e) { if (e != null && e.Count > 0) { for (int i = 0; i < e.Count; i++) { AnnotEditEvent editEvent = e[i]; switch (editEvent.EditAction) { case ActionType.Add: BOTAContentViewModel bOTAContentViewModel = null; bool isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel); if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true) { AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel); if (viewModel != null) { int pageindex = editEvent.PageIndex; int annotindex = editEvent.AnnotIndex; viewModel.UpdateAddedAnnot(pageindex, annotindex); } } break; case ActionType.Del: isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel); if (isTabItemAnnotation) { AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel); if (viewModel != null) { int pageindex = editEvent.PageIndex; int annotindex = editEvent.AnnotIndex; viewModel.UpdateModifiedAnnot(pageindex, annotindex, true); } } break; case ActionType.Modify: isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel); if (isTabItemAnnotation) { AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel); if (viewModel != null) { int pageindex = editEvent.PageIndex; int annotindex = editEvent.AnnotIndex; viewModel.UpdateModifiedAnnot(pageindex, annotindex, false); } } break; case ActionType.TextEdit: break; default: break; } } } } private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel) { AnnotationContentViewModel viewModel = null; if (bOTAContentViewModel != null) { if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName)) { var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views; foreach (var item in views) { if (item is AnnotationContent annotation) { viewModel = annotation.DataContext as AnnotationContentViewModel; break; } } } } return viewModel; } private bool IsTabItemAnnotationShow(out BOTAContentViewModel bOTAContentViewModel) { bool isTabItemAnnotation = false; bOTAContentViewModel = null; if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName)) { var views = region.Regions[viewContentViewModel.BOTARegionName].Views; foreach (var item in views) { if (item is BOTAContent bOTAContent) { bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel; if (bOTAContentViewModel.CurrentBar == "TabItemAnnotation") { isTabItemAnnotation = true; break; } } } } return isTabItemAnnotation; } private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e) { if (e != null) { var annot = e.AnnotItemsList[0]; if (annot != null) { if (e.AnnotItemsList.Count == 1 && e.IsAnnotCreateReset == false) { switch (annot.EventType) { case AnnotArgsType.AnnotHighlight: e.IsAnnotCreateReset = false; GetHighLight(annot as TextHighlightAnnotArgs); break; case AnnotArgsType.AnnotUnderline: GetUnderLine(annot as TextUnderlineAnnotArgs); break; case AnnotArgsType.AnnotStrikeout: GetStrikeout(annot as TextStrikeoutAnnotArgs); break; case AnnotArgsType.AnnotSquiggly: GetSquiggly(annot as TextSquigglyAnnotArgs); break; case AnnotArgsType.AnnotFreehand: GetFreehand(annot as FreehandAnnotArgs); break; case AnnotArgsType.AnnotFreeText: GetFreetext(annot as FreeTextAnnotArgs); break; case AnnotArgsType.AnnotSquare: GetRect(annot as SquareAnnotArgs); break; case AnnotArgsType.AnnotCircle: GetCircle(annot as CircleAnnotArgs); break; case AnnotArgsType.AnnotLine: bool isLine = true; if (e.Attribs.ContainsKey(AnnotAttrib.LineStart)) { if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE) { isLine = false; } } if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd)) { if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE) { isLine = false; } } if (isLine) GetArrowLine("Line", annot as LineAnnotArgs); else GetArrowLine("Arrow", annot as LineAnnotArgs); break; case AnnotArgsType.AnnotLink: viewContentViewModel.IsCreateLink = false; GetLink(annot as LinkAnnotArgs, e); break; case AnnotArgsType.AnnotSticky: GetStickyNote(annot as StickyAnnotArgs); break; } ShowPropertyPanel(); } else if (e.AnnotItemsList.Count == 1 && e.IsAnnotCreateReset == true) { switch (annot.EventType) { case AnnotArgsType.AnnotLink: GetLink(annot as LinkAnnotArgs, e); break; } ShowPropertyPanel(); } } } else { // PDFViewer.SetMouseMode(MouseModes.AnnotCreate); // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); } } private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e) { if (e.AnnotEventArgsList == null) return; // var annotlist = e.AnnotEventArgsList; switch (e.CommandType) { case CommandType.Context: if (e.AnnotEventArgsList.Count > 0) { if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction) { //绑定标记密文处右键菜单 events.GetEvent().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e }); } else { e.PopupMenu = SelectAnnotContextMenu(sender); } if (e.PopupMenu != null) { e.Handle = true; } } else { if (e.PressOnSelectedText) { e.PopupMenu = NoneSelectAnnotContextMenu(sender, e); if (e.PopupMenu != null) { e.Handle = true; } } else { e.PopupMenu = ViewerContextMenu(); if (e.PopupMenu != null) { e.Handle = true; } } } break; } } private ContextMenu ViewerContextMenu() { ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu; contextMenu.Loaded += ContextMenu_Loaded; return contextMenu; } private void ContextMenu_Loaded(object sender, RoutedEventArgs e) { ContextMenu contextMenu = sender as ContextMenu; if (contextMenu.Items.Count > 0) { //粘贴 MenuItem menuItem = contextMenu.Items[0] as MenuItem; if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender)) { menuItem.IsEnabled = false; menuItem.Opacity = 0.5; } else { menuItem.IsEnabled = true; menuItem.Opacity = 1; } //添加注释 > MenuItem menuItem1 = contextMenu.Items[2] as MenuItem; if (menuItem1.Items.Count > 0) { SetAddAnnotation(menuItem1.Items); } //隐藏注释 > MenuItem menuItem2 = contextMenu.Items[3] as MenuItem; //显示注释 > MenuItem menuItem3 = contextMenu.Items[4] as MenuItem; if (menuItem2.Visibility == Visibility.Visible) { menuItem3.Visibility = Visibility.Collapsed; } else { menuItem3.Visibility = Visibility.Visible; } //添加书签 > MenuItem menuItem4 = contextMenu.Items[5] as MenuItem; //删除书签 > MenuItem menuItem5 = contextMenu.Items[6] as MenuItem; if (menuItem4.Visibility == Visibility.Visible) { menuItem5.Visibility = Visibility.Collapsed; } else { menuItem5.Visibility = Visibility.Visible; } //工具模式 > MenuItem menuItem6 = contextMenu.Items[8] as MenuItem; //进入阅读模式 > MenuItem menuItem7 = contextMenu.Items[9] as MenuItem; //退出阅读模式 > MenuItem menuItem8 = contextMenu.Items[10] as MenuItem; if (App.IsBookMode) { menuItem7.Visibility = Visibility.Visible; } else { menuItem7.Visibility = Visibility.Collapsed; } if (menuItem7.Visibility == Visibility.Visible) { menuItem8.Visibility = Visibility.Collapsed; } else { menuItem8.Visibility = Visibility.Visible; } //视图缩放 > MenuItem menuItem9 = contextMenu.Items[12] as MenuItem; //页面显示 > MenuItem menuItem10 = contextMenu.Items[13] as MenuItem; //查找 MenuItem menuItem11 = contextMenu.Items[15] as MenuItem; //打印... MenuItem menuItem12 = contextMenu.Items[16] as MenuItem; } } private void SetAddAnnotation(ItemCollection items) { foreach (var item in items) { if (item is MenuItem menuItem) { menuItem.CommandParameter = item; menuItem.Command = SetAddAnnotationCommand; } } } private void AddAnnotation_Click(object sender) { if (sender is MenuItem menuItem) { AnnotHandlerEventArgs annotHandler = null; if (menuItem.Tag.ToString() == AddAnnotType.AnnotFreeText.ToString()) { annotHandler = GetFreetext(); //if (annotHandler != null) //{ // annotHandler.Author = Settings.Default.AppProperties.Description.Author; // PDFViewer.SetMouseMode(MouseModes.AnnotCreate); // PDFViewer.SetToolParam(annotHandler); // ShowPropertyPanel(true); //} } if (menuItem.Tag.ToString() == AddAnnotType.AnnotLine.ToString()) { annotHandler = GetArrowLine("Line"); //if (annotHandler != null) //{ // annotHandler.Author = Settings.Default.AppProperties.Description.Author; // PDFViewer.SetMouseMode(MouseModes.AnnotCreate); // PDFViewer.SetToolParam(annotHandler); // ShowPropertyPanel(true); //} } if (annotHandler != null) { annotHandler.Author = Settings.Default.AppProperties.Description.Author; PDFViewer.SetMouseMode(MouseModes.AnnotCreate); PDFViewer.SetToolParam(annotHandler); ShowPropertyPanel(true); } } //if (sender is AnnotHandlerEventArgs annotHandler) //{ // if (annotHandler != null) // { // annotHandler.Author = Settings.Default.AppProperties.Description.Author; // PDFViewer.SetMouseMode(MouseModes.AnnotCreate); // PDFViewer.SetToolParam(annotHandler); // ShowPropertyPanel(true); // } //} } private ContextMenu SelectAnnotContextMenu(object sender) { var popMenu = App.Current.FindResource("SelectAnnotContextMenu") as ContextMenu; if (popMenu != null && popMenu.Items.Count == 4) { //剪切 MenuItem menuItem = popMenu.Items[0] as MenuItem; menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Cut; //复制 menuItem = popMenu.Items[1] as MenuItem; menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Copy; //删除 menuItem = popMenu.Items[2] as MenuItem; menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Delete; //笔记 //menuItem = popMenu.Items[2] as MenuItem; //menuItem.CommandTarget = (UIElement)sender; //menuItem.Command = ApplicationCommands.no; } return popMenu; } private ContextMenu NoneSelectAnnotContextMenu(object sender, AnnotCommandArgs annotCommand) { var popMenu = new ContextMenu(); MenuItem menuItem = new MenuItem(); menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Paste; popMenu.Items.Add(menuItem); menuItem = new MenuItem(); menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Copy; popMenu.Items.Add(menuItem); menuItem = new MenuItem(); menuItem.CommandTarget = (UIElement)sender; menuItem.Header = "创建链接"; menuItem.CommandParameter = new object[] { this, annotCommand }; menuItem.Command = viewContentViewModel.CreateLinkCommand; menuItem.Click += MenuItem_Click; popMenu.Items.Add(menuItem); return popMenu; } private void MenuItem_Click(object sender, RoutedEventArgs e) { var args = PDFViewer.ToolManager.CurrentAnnotArgs; BtnLinkIsChecked = true; } /// /// 展开显示属性面板 /// private void ShowPropertyPanel(bool show = true) { viewContentViewModel.IsPropertyOpen = show; } } }