123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Office.Model;
- using PDF_Office.ViewModels.Tools;
- 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.Controls.Primitives;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
- {
- public class FreehandAnnotPropertyViewModel : BindableBase, INavigationAware
- {
- private Brush selectColor = new SolidColorBrush(Colors.Transparent);
- public Brush SelectColor
- {
- get { return selectColor; }
- set { SetProperty(ref selectColor, value); SetAnnotProperty(); }
- }
- private double annotOpacity = 1;
- public double AnnotOpacity
- {
- get { return annotOpacity; }
- set
- {
- SetProperty(ref annotOpacity, value);
- }
- }
- private double thicknessLine = 1;
- public double ThicknessLine
- {
- get { return thicknessLine; }
- set
- {
- SetProperty(ref thicknessLine, value); SetAnnotProperty();
- }
- }
- private FreehandAnnotArgs Annot;
- private AnnotPropertyPanel PropertyPanel;
- public DelegateCommand<object> EraseCommand { get; set; }
- public DelegateCommand<object> PenCommand { get; set; }
- public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
- public DelegateCommand<object> SelectedValueChangedCommand { get; set; }
- public FreehandAnnotPropertyViewModel()
- {
- EraseCommand = new DelegateCommand<object>(Erase_Command);
- PenCommand = new DelegateCommand<object>(Pen_Command);
- SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
- SelectedValueChangedCommand = new DelegateCommand<object>(SelectedValueChanged_Command);
- }
- private void SelectedValueChanged_Command(object obj)
- {
- if (obj != null)
- {
- annotOpacity = (double)obj;
- SelectColor.Opacity = annotOpacity;
- SetAnnotProperty();
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = annotOpacity;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- private void SelectedColorChanged_Click(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- SelectColor = new SolidColorBrush(colorValue);
- SelectColor.Opacity = AnnotOpacity;
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = obj;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- }
- private void Erase_Command(object obj)
- {
- var btn = obj as ToggleButton;
- if(btn.IsChecked == true)
- {
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotErase] = btn;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- private void Pen_Command(object obj)
- {
- var btn = obj as ToggleButton;
- if (btn.IsChecked == true)
- {
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotErase] = btn;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
- if (PropertyPanel != null)
- {
- Annot = PropertyPanel.annot as FreehandAnnotArgs;
- }
- }
- private void SetAnnotProperty()
- {
- if (Annot != null)
- {
- if (Annot is FreehandAnnotArgs)
- {
- if (Annot.Transparency != AnnotOpacity)
- Annot.Transparency = AnnotOpacity;
- if (Annot.LineWidth != ThicknessLine)
- Annot.LineWidth = ThicknessLine;
- var c = (SelectColor as SolidColorBrush).Color;
- if (Annot.InkColor.A != c.A || Annot.InkColor.B != c.B || Annot.InkColor.G != c.G || Annot.InkColor.R != c.R)
- Annot.InkColor = (SelectColor as SolidColorBrush).Color;
- }
- }
- }
- }
- }
|