using ComPDFKitViewer.AnnotEvent; using PDF_Office.Model; using PDF_Office.ViewModels.Tools; using PDFSettings; 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; using System.Windows.Media; namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel { public class TextAnnotPropertyViewModel:BindableBase, INavigationAware { #region 属性 private double annotOpacity; public double AnnotOpacity { get { return annotOpacity; } set { SetProperty(ref annotOpacity, value); SampleTextBg.Opacity = annotOpacity; SetAnnotProperty(); Dictionary changeData = new Dictionary(); changeData[AnnotType] = annotOpacity; PropertyPanel.DataChangedInvoke(this, changeData); } } private AnnotArgsType annotType; public AnnotArgsType AnnotType { get { return annotType; } set { SetProperty(ref annotType, value); SetAnnotType(); } } /// /// 示例背景 /// private Brush sampleTextBg = new SolidColorBrush(Colors.Transparent); public Brush SampleTextBg { get { return sampleTextBg; } set { SetProperty(ref sampleTextBg, value); SetAnnotProperty(); } } private string annotTypeTitle; public string AnnotTypeTitle { get { return annotTypeTitle; } set { SetProperty(ref annotTypeTitle, value); } } private Color selectColor; public Color SelectColor { get { return selectColor; } set { SetProperty(ref selectColor, value); SetAnnotProperty(); } } #endregion public DelegateCommand SelectedColorChangedCommand { get; set; } public DelegateCommand OpacityItemCommand { get; set; } public TextAnnotPropertyViewModel() { SelectedColorChangedCommand = new DelegateCommand(SelectedColorChanged_Click); OpacityItemCommand = new DelegateCommand(OpacityItemCommand_Click); } private void OpacityItemCommand_Click(object obj) { if(obj!= null) { int opacity = -1; if(int.TryParse((string)obj, out opacity)) { AnnotOpacity = opacity/100D; Dictionary changeData = new Dictionary(); changeData[AnnotType] = AnnotOpacity; PropertyPanel.DataChangedInvoke(this, changeData); } } } public void SelectedColorChanged_Click(object color) { if (color != null) { var colorValue = (Color)color; if (colorValue != null) { SampleTextBg = new SolidColorBrush(colorValue); switch(AnnotType) { case AnnotArgsType.AnnotHighlight: SampleTextBg.Opacity = AnnotOpacity; break; case AnnotArgsType.AnnotUnderline: SampleTextBg.Opacity = AnnotOpacity; break; case AnnotArgsType.AnnotStrikeout: SampleTextBg.Opacity = AnnotOpacity; break; case AnnotArgsType.AnnotSquiggly: SampleTextBg.Opacity = AnnotOpacity; break; case AnnotArgsType.AnnotSticky: SampleTextBg.Opacity = AnnotOpacity; break; } Dictionary changeData = new Dictionary(); changeData[AnnotType] = color; PropertyPanel.DataChangedInvoke(this, changeData); // PropertyPanel.DataChanged?.Invoke(this, changeData); } } } private void SetAnnotType() { switch (AnnotType) { case AnnotArgsType.AnnotHighlight: AnnotTypeTitle = "高亮"; break; case AnnotArgsType.AnnotUnderline: AnnotTypeTitle = "下划线"; break; case AnnotArgsType.AnnotStrikeout: AnnotTypeTitle = "删除线"; break; case AnnotArgsType.AnnotSquiggly: AnnotTypeTitle = "波浪线"; break; case AnnotArgsType.AnnotSticky: AnnotTypeTitle = "??"; break; } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } private ComPDFKitViewer.PdfViewer.CPDFViewer PDFViewer; private AnnotHandlerEventArgs Annot; private AnnotPropertyPanel PropertyPanel; public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); if(PropertyPanel != null) { Annot = PropertyPanel.annot; GetAnnotProperty(); } } private void GetAnnotProperty() { if (Annot != null) { SampleTextBg = new SolidColorBrush(Colors.Transparent); switch (Annot.EventType) { case AnnotArgsType.AnnotHighlight: if (Annot is TextHighlightAnnotArgs) { var Hightlight = Annot as TextHighlightAnnotArgs; AnnotOpacity = Hightlight.Transparency; AnnotType = Hightlight.EventType; SampleTextBg = new SolidColorBrush(Hightlight.Color); } break; case AnnotArgsType.AnnotUnderline: { var Underline = Annot as TextUnderlineAnnotArgs; AnnotOpacity = Underline.Transparency; AnnotType = Underline.EventType; } break; case AnnotArgsType.AnnotSquiggly: { var Underline = Annot as TextSquigglyAnnotArgs; AnnotOpacity = Underline.Transparency; AnnotType = Underline.EventType; } break; //case AnnotArgsType.AnnotStrikeout: // { // var Underline = Annot as TextStrikeoutAnnotArgs; // AnnotOpacity = Underline.Transparency; // AnnotType = Underline.EventType; // } // break; } } } private void SetAnnotProperty() { if (Annot != null) { switch (Annot.EventType) { case AnnotArgsType.AnnotHighlight: if (Annot is TextHighlightAnnotArgs) { var Hightlight = Annot as TextHighlightAnnotArgs; if (Hightlight.Transparency != AnnotOpacity) Hightlight.Transparency = AnnotOpacity; var c = (SampleTextBg as SolidColorBrush).Color; if (Hightlight.Color.A != c.A || Hightlight.Color.B != c.B || Hightlight.Color.G != c.G || Hightlight.Color.R != c.R) Hightlight.Color = (SampleTextBg as SolidColorBrush).Color; } break; case AnnotArgsType.AnnotUnderline: { var Underline = Annot as TextUnderlineAnnotArgs; if (Underline.Transparency != AnnotOpacity) Underline.Transparency = AnnotOpacity; } break; case AnnotArgsType.AnnotSquiggly: { var Squiggly = Annot as TextSquigglyAnnotArgs; if (Squiggly.Transparency != AnnotOpacity) AnnotOpacity = Squiggly.Transparency; } break; case AnnotArgsType.AnnotStrikeout: { var Strikeout = Annot as TextStrikeoutAnnotArgs; if (Strikeout.Transparency != AnnotOpacity) Strikeout.Transparency = AnnotOpacity; } break; } } } } }