123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.Model;
- using PDF_Master.Properties;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Master.ViewModels.PropertyPanel.ViewModular
- {
- public class ReadViewContentViewModel : BindableBase, INavigationAware
- {
- #region 文案
- private string T_ESCreadMode;
- public string T_ESCReadMode
- {
- get { return T_ESCreadMode; }
- set
- {
- SetProperty(ref T_ESCreadMode, value);
- }
- }
- private void InitString()
- {
- T_ESCReadMode = App.MainPageLoader.GetString("GlobalTip_ESCReadMode");
- }
- #endregion
- public string ReadRegionName { get; set; }
- public string ReadModeRegionName { get; set; }
- public ViewContentViewModel ViewContentViewModel { get; set; }
- public CPDFViewer PDFViewer { get; set; }
- private Visibility pressEscTip = Visibility.Visible;
- public Visibility PressEscTip
- {
- get { return pressEscTip; }
- set
- {
- SetProperty(ref pressEscTip, value);
- }
- }
- private bool canSave;
- /// <summary>
- /// 是否可以保存
- /// </summary>
- public bool CanSave
- {
- get { return canSave; }
- set
- {
- SetProperty(ref canSave, value);
- }
- }
- private bool canUndo;
- /// <summary>
- /// 是否可以进行Undo
- /// </summary>
- public bool CanUndo
- {
- get { return canUndo; }
- set
- {
- SetProperty(ref canUndo, value);
- }
- }
- private bool canRedo;
- /// <summary>
- /// 是否可以进行Redo
- /// </summary>
- public bool CanRedo
- {
- get { return canRedo; }
- set
- {
- SetProperty(ref canRedo, value);
- }
- }
- private Visibility readModeContentVisibility = Visibility.Collapsed;
- public Visibility ReadModeContentVisibility
- {
- get { return readModeContentVisibility; }
- set
- {
- SetProperty(ref readModeContentVisibility, value);
- }
- }
- private Visibility rectangleReadModeVisibility = Visibility.Collapsed;
- public Visibility RectangleReadModeVisibility
- {
- get { return rectangleReadModeVisibility; }
- set
- {
- SetProperty(ref rectangleReadModeVisibility, value);
- }
- }
- public IRegionManager region;
- public IDialogService dialogs;
- /// <summary>
- /// 鼠标滚轮缩放的缩放值
- /// </summary>
- private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
- public DelegateCommand Load { get; set; }
- public ReadViewContentViewModel(IRegionManager regionManager, IDialogService dialogService)
- {
- region = regionManager;
- dialogs = dialogService;
- ReadRegionName = RegionNames.ReadRegionName;
- ReadModeRegionName = RegionNames.ReadModePageRegionName;
- ReadModeContentVisibility = Visibility.Visible;
- RectangleReadModeVisibility = Visibility.Collapsed;
- InitString();
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
- pdfview.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGroundInFulWindow));
- ViewContentViewModel viewContentView = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
- if (pdfview != null)
- {
- PDFViewer = pdfview;
- PressEscTip = Visibility.Visible;
- LoadFile();
- await System.Threading.Tasks.Task.Delay(3000);
- PressEscTip = Visibility.Collapsed;
- }
- if (viewContentView != null)
- {
- ViewContentViewModel = viewContentView;
- }
- }
- /// <summary>
- /// 将PDFViwer添加到Region
- /// </summary>
- private void LoadFile()
- {
- PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
- PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
- CanSave = PDFViewer.UndoManager.CanSave;
- CanUndo = PDFViewer.UndoManager.CanUndo;
- CanRedo = PDFViewer.UndoManager.CanRedo;
- if (region.Regions.ContainsRegionWithName(ReadRegionName))
- {
- if (region.Regions[ReadRegionName].Views.Contains(PDFViewer))
- {
- var contentRegion = region.Regions[ReadRegionName];
- contentRegion.Remove(PDFViewer);
- }
- region.AddToRegion(ReadRegionName, PDFViewer);
- }
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- NavigationParameters parameters = new NavigationParameters();
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
- }
- ));
- }
- public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
- {
- double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
- PDFViewer.Zoom(newZoom);
- }
- private double CheckZoomLevel(double zoom, bool IsGrowth)
- {
- double standardZoom = 100;
- if (zoom <= 0.01)
- {
- return 0.01;
- }
- if (zoom >= 10)
- {
- return 10;
- }
- zoom *= 100;
- for (int i = 0; i < zoomLevel.Length - 1; i++)
- {
- if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
- {
- standardZoom = zoomLevel[i + 1];
- break;
- }
- if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
- {
- standardZoom = zoomLevel[i];
- break;
- }
- }
- return standardZoom / 100;
- }
- private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
- //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
- if (e.PropertyName == "CanUndo")
- {
- CanUndo = PDFViewer.UndoManager.CanUndo;
- }
- if (e.PropertyName == "CanRedo")
- {
- CanRedo = PDFViewer.UndoManager.CanRedo;
- }
- if (e.PropertyName == "CanSave")
- {
- CanSave = PDFViewer.UndoManager.CanSave;
- }
- }
- }
- }
|