12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using ComPDFKitViewer.PdfViewer;
- using Prism.Commands;
- using Prism.Regions;
- using System.Windows;
- using PDF_Master.Views;
- using ComPDFKitViewer;
- using System.Windows.Input;
- using System.Windows.Controls;
- using Prism.Services.Dialogs;
- using PDF_Master.CustomControl;
- using PDF_Master.Model;
- using PDF_Master.ViewModels.BOTA;
- using PDF_Master.Views.BOTA;
- using PDF_Master.Views.PropertyPanel.AnnotPanel;
- using PDF_Master.Views.Tools;
- using PDFSettings;
- using PDF_Master.Helper;
- using System.IO;
- using ImTools;
- using PDF_Master.Views.PropertyPanel.ViewModular;
- namespace PDF_Master.ViewModels
- {
- public class BottomToolContentViewModel : BindableBase, INavigationAware
- {
- #region 文案
- private string T_actual;
- public string T_Actual
- {
- get { return T_actual; }
- set
- {
- SetProperty(ref T_actual, value);
- }
- }
- private string T_fitWidth;
- public string T_FitWidth
- {
- get { return T_fitWidth; }
- set
- {
- SetProperty(ref T_fitWidth, value);
- }
- }
- private string T_fitPage;
- public string T_FitPage
- {
- get { return T_fitPage; }
- set
- {
- SetProperty(ref T_fitPage, value);
- }
- }
- private string T_continuousText;
- public string T_ContinuousText
- {
- get { return T_continuousText; }
- set
- {
- SetProperty(ref T_continuousText, value);
- }
- }
- private string T_continuousTip;
- public string T_ContinuousTip
- {
- get { return T_continuousTip; }
- set
- {
- SetProperty(ref T_continuousTip, value);
- }
- }
- private string T_singlePageText;
- public string T_SinglePageText
- {
- get { return T_singlePageText; }
- set
- {
- SetProperty(ref T_singlePageText, value);
- }
- }
- private string T_singlePageTip;
- public string T_SinglePageTip
- {
- get { return T_singlePageTip; }
- set
- {
- SetProperty(ref T_singlePageTip, value);
- }
- }
- private string T_facingText;
- public string T_FacingText
- {
- get { return T_facingText; }
- set
- {
- SetProperty(ref T_facingText, value);
- }
- }
- private string T_facingTip;
- public string T_FacingTip
- {
- get { return T_facingTip; }
- set
- {
- SetProperty(ref T_facingTip, value);
- }
- }
- private string T_bookModeTip;
- public string T_BookModeTip
- {
- get { return T_bookModeTip; }
- set
- {
- SetProperty(ref T_bookModeTip, value);
- }
- }
- private string T_bookModeText;
- public string T_BookModeText
- {
- get { return T_bookModeText; }
- set
- {
- SetProperty(ref T_bookModeText, value);
- }
- }
- //private string T_showViewModularTip;
- //public string T_ShowViewModularTip
- //{
- // get { return T_showViewModularTip; }
- // set
- // {
- // SetProperty(ref T_showViewModularTip, value);
- // }
- //}
- private string T_showViewModularText;
- public string T_ShowViewModularText
- {
- get { return T_showViewModularText; }
- set
- {
- SetProperty(ref T_showViewModularText, value);
- }
- }
- private void InitString()
- {
- T_Actual = App.MainPageLoader.GetString("Zoom_Actual");
- T_FitWidth = App.MainPageLoader.GetString("Zoom_FitWidth");
- T_FitPage = App.MainPageLoader.GetString("Zoom_FitPage");
- T_ContinuousText = App.MainPageLoader.GetString("MainPage_Continuous");
- T_ContinuousTip = App.MainPageLoader.GetString("MainPage_ViewPageContinousTip");
- T_SinglePageText = App.MainPageLoader.GetString("MainPage_SinglePage");
- T_SinglePageTip = App.MainPageLoader.GetString("MainPage_SinglePageTip");
- T_FacingText = App.MainPageLoader.GetString("MainPage_Facing");
- T_FacingTip = App.MainPageLoader.GetString("MainPage_FacingTip");
- T_BookModeText = App.MainPageLoader.GetString("MainPage_BookMode");
- T_BookModeTip = App.MainPageLoader.GetString("MainPage_BookModeTip");
- T_ShowViewModularText = App.MainPageLoader.GetString("MainPage_ShowViewModular");
- //T_ShowViewModularTip = App.MainPageLoader.GetString("MainPage_ShowViewModularTip");
- }
- #endregion 文案
- public DelegateCommand Load { get; set; }
- public DelegateCommand FirstPageCommand { get; set; }
- public DelegateCommand LastPageCommand { get; set; }
- public DelegateCommand PrePageCommand { get; set; }
- public DelegateCommand NextPageCommand { get; set; }
- public DelegateCommand MyPropertyCommand { get; set; }
- public DelegateCommand FullScreenCommand { get; set; }
- public DelegateCommand ReadModeCommand { get; set; }
- public DelegateCommand OpenViewCommand { get; set; }
- public DelegateCommand ZoomInCommand { get; set; }
- public DelegateCommand ZoomOutCommand { get; set; }
- public DelegateCommand SetViewModeCommand { get; set; }
- public DelegateCommand OpenFullCommand { get; set; }
- public DelegateCommand<object> PageTextKeyDownCommand { get; set; }
- public DelegateCommand<object> PageTextPreviewKeyDownCommand { get; set; }
- public DelegateCommand<object> SelectionChangedCommand { get; set; }
- public DelegateCommand<object> ShowViewModularCommand { get; set; }
- /// <summary>
- /// 上一个视图
- /// </summary>
- public DelegateCommand PreViewCommand { get; set; }
- /// <summary>
- /// 下一个视图
- /// </summary>
- public DelegateCommand NextViewCommnad { get; set; }
- /// <summary>
- /// 拦截键盘输入的事件
- /// </summary>
- public DelegateCommand<object> PreviewKeyDown { get; set; }
- /// <summary>
- /// 进入单页
- /// </summary>
- public DelegateCommand SinglePageCommand { get; set; }
- /// <summary>
- /// 进入双页
- /// </summary>
- public DelegateCommand DoublePageCommand { get; set; }
- /// <summary>
- /// 回到实际大小
- /// </summary>
- public DelegateCommand RealSizeCommand { get; set; }
- private bool isShowViewModular = false;
- /// <summary>
- /// 是否已经显示 用于跳过控件显示前触发的事件
- /// </summary>
- public bool IsLoaded = false;
- /// <summary>
- /// 属性栏是否展开
- /// </summary>
- public bool IsShowViewModular
- {
- get { return isShowViewModular; }
- set
- {
- SetProperty(ref isShowViewModular, value);
- }
- }
- private bool isSingleView;
- public bool IsSingleView
- {
- get { return isSingleView; }
- set
- {
- SetProperty(ref isSingleView, value);
- if (value)
- {
- SetModeView();
- }
- }
- }
- private bool isContinue;
- public bool IsContinue
- {
- get { return isContinue; }
- set
- {
- SetProperty(ref isContinue, value);
- SetModeView();
- }
- }
- private bool isDoubleView;
- public bool IsDoubleView
- {
- get { return isDoubleView; }
- set
- {
- SetProperty(ref isDoubleView, value);
- if (value)
- {
- SetModeView();
- }
- }
- }
- private bool isBookMode;
- public bool IsBookMode
- {
- get { return isBookMode; }
- set
- {
- SetProperty(ref isBookMode, value);
- if (value)
- {
- SetModeView();
- }
- }
- }
- private int pageCount;
- public int PageCount
- {
- get { return pageCount; }
- set
- {
- SetProperty(ref pageCount, value);
- }
- }
- private int currentPage;
- public int CurrentPage
- {
- get { return currentPage; }
- set
- {
- SetProperty(ref currentPage, value);
- }
- }
- private double currenZoom;
- public double CurrentZoom
- {
- get { return currenZoom; }
- set { SetProperty(ref currenZoom, value); }
- }
- private int selectedIndex;
- public int SelectedIndex
- {
- get { return selectedIndex; }
- set
- {
- SetProperty(ref selectedIndex, value);
- }
- }
- private bool rightPanelEnable = true;
- public bool RightPanelEnable
- {
- get { return rightPanelEnable; }
- set
- {
- SetProperty(ref rightPanelEnable, value);
- }
- }
- private bool isPreEnable = false;
- /// <summary>
- /// 前进是否启用
- /// </summary>
- public bool IsPreEnable
- {
- get { return isPreEnable; }
- set
- {
- SetProperty(ref isPreEnable, value);
- }
- }
- private bool isNextEnable = false;
- public bool IsNextEnable
- {
- get { return isNextEnable; }
- set
- {
- SetProperty(ref isNextEnable, value);
- }
- }
- private Stack<int> UndoStack = new Stack<int>();
- private Stack<int> RedoStack = new Stack<int>();
- public CPDFViewer PDFViewer { get; set; }
- public ViewContentViewModel ViewContentViewModel { get; set; }
- public OpenFileInfo OpenFileInfo = null;
- /// <summary>
- /// 来自undo redo方法的跳页 不计入栈
- /// </summary>
- private bool isFromMethod = false;
- /// <summary>
- /// 记录上一个页面索引值
- /// </summary>
- private int oldPageIndex = 0;
- private IRegionManager region;
- private IDialogService dialogs;
- public BottomToolContentViewModel(IRegionManager regionManager, IDialogService dialogService)
- {
- region = regionManager;
- dialogs = dialogService;
- PrePageCommand = new DelegateCommand(GoPrePage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
- NextPageCommand = new DelegateCommand(GoNextPage, CanNextPageExcute).ObservesProperty(() => CurrentPage);
- FirstPageCommand = new DelegateCommand(GoFirstPage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
- LastPageCommand = new DelegateCommand(GoLastPage, CanNextPageExcute).ObservesProperty(() => CurrentPage);
- ZoomInCommand = new DelegateCommand(ZoomIn, CanZoomIn).ObservesProperty(() => CurrentZoom);
- ZoomOutCommand = new DelegateCommand(ZoomOut, CanZoomOut).ObservesProperty(() => CurrentZoom);
- SetViewModeCommand = new DelegateCommand(SetModeView);
- PageTextKeyDownCommand = new DelegateCommand<object>(PageNumText_KeyDown);
- PageTextPreviewKeyDownCommand = new DelegateCommand<object>(PageNumText_PreviewKeyDown);
- SelectionChangedCommand = new DelegateCommand<object>(SelectionChangedEvent);
- ShowViewModularCommand = new DelegateCommand<object>(ShowViewModularEvent);
- PreviewKeyDown = new DelegateCommand<object>(previewkeydown);
- PreViewCommand = new DelegateCommand(undo);
- SinglePageCommand = new DelegateCommand(() => { IsSingleView = true; });
- DoublePageCommand = new DelegateCommand(() => { IsDoubleView = true; });
- RealSizeCommand = new DelegateCommand(ZoomToRealSize);
- NextViewCommnad = new DelegateCommand(redo);
- InitString();
- }
- /// <summary>
- /// 缩放至实际大小
- /// </summary>
- private void ZoomToRealSize()
- {
- PDFViewer?.ChangeFitMode(FitMode.FitSize);
- if (OpenFileInfo != null)
- {
- OpenFileInfo.LastFitMode = FitMode.FitSize;
- }
- }
- private void previewkeydown(object e)
- {
- var args = e as KeyEventArgs;
- if (args == null)
- {
- return;
- }
- //输入值的预处理通过input事件里写正则来判断
- if (args.Key == Key.Enter)
- {
- var text = (args.OriginalSource as TextBox);
- int zoom = int.Parse(text.Text.Replace("%", ""));
- PDFViewer?.Zoom(zoom / 100.0);
- }
- }
- private void undo()
- {
- if (!IsPreEnable)
- {
- return;
- }
- RedoStack.Push(PDFViewer.CurrentIndex);
- IsNextEnable = true;
- App.Current.Dispatcher.Invoke(() =>
- {
- int index = UndoStack.Pop();
- PDFViewer.GoToPage(index);
- if (UndoStack.Count <= 0)
- {
- IsPreEnable = false;
- }
- });
- isFromMethod = true;
- }
- private void redo()
- {
- if (!IsNextEnable)
- {
- return;
- }
- App.Current.Dispatcher.Invoke(() =>
- {
- UndoStack.Push(PDFViewer.CurrentIndex);
- IsPreEnable = true;
- int index = RedoStack.Pop();
- PDFViewer.GoToPage(index);
- if (RedoStack.Count <= 0)
- {
- IsNextEnable = false;
- }
- });
- isFromMethod = true;
- }
- private void ShowViewModularEvent(object obj)
- {
- if (region.Regions.ContainsRegionWithName(ViewContentViewModel.PropertyRegionName))
- {
- var check = (bool)obj;
- if (check)
- {
- ViewContentViewModel.IsPropertyOpen = true;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.BottomToolContentViewModel, this);
- region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
- }
- else
- {
- ViewContentViewModel.IsPropertyOpen = false;
- region.RequestNavigate(RegionNames.PropertyRegionName, "PropertyPanelContent");
- }
- }
- }
- private void SelectionChangedEvent(object e)
- {
- if (e == null)
- {
- return;
- }
- var args = e as SelectionChangedEventArgs;
- if (args != null)
- {
- if (SelectedIndex <= 2)
- {
- switch (SelectedIndex)
- {
- case 0:
- PDFViewer?.ChangeFitMode(FitMode.FitSize);
- if (OpenFileInfo != null)
- {
- OpenFileInfo.LastFitMode = FitMode.FitSize;
- }
- break;
- case 1:
- PDFViewer?.ChangeFitMode(FitMode.FitWidth);
- if (OpenFileInfo != null)
- {
- OpenFileInfo.LastFitMode = FitMode.FitWidth;
- }
- break;
- case 2:
- PDFViewer?.ChangeFitMode(FitMode.FitHeight);
- if (OpenFileInfo != null)
- {
- OpenFileInfo.LastFitMode = FitMode.FitHeight;
- }
- break;
- default:
- break;
- }
- }
- else
- {
- if (args.AddedItems[0] is ComboBoxItem)
- {
- if ((args.AddedItems[0] as ComboBoxItem).Tag != null)
- {
- PDFViewer?.Zoom(Convert.ToDouble((args.AddedItems[0] as ComboBoxItem).Tag.ToString()) / 100.0);
- }
- }
- }
- }
- }
- private void PageNumText_PreviewKeyDown(object e)
- {
- var args = e as KeyEventArgs;
- if (args != null)
- {
- //显示文本框输入内容
- List<Key> NumberKeys = new List<Key>() { Key.D0,Key.D1,Key.D2,Key.D3,Key.D4,Key.D5,Key.D6,Key.D7,Key.D8,Key.D9,Key.NumPad0,Key.NumPad1,Key.NumPad2,
- Key.NumPad3,Key.NumPad4,Key.NumPad5,Key.NumPad6,Key.NumPad7,Key.NumPad8,Key.NumPad9,Key.Delete,Key.Back,Key.Enter,Key.Right,Key.Left};
- if (!NumberKeys.Contains(args.Key))
- {
- args.Handled = true;
- }
- }
- }
- private void PageNumText_KeyDown(object e)
- {
- if (!(e is KeyEventArgs))
- return;
- //回车提交输入
- if ((e as KeyEventArgs).Key == System.Windows.Input.Key.Enter)
- {
- int pagenum = 0;
- string text = ((e as KeyEventArgs).OriginalSource as TextBox).Text.ToString();
- char[] chs = { ' ', '/', '\\' };//字符截取 拒止非法输入
- int i = text.LastIndexOfAny(chs);
- if (i > 0)
- text = text.Substring(0, i - 1);
- if (!int.TryParse(text, out pagenum))
- {
- CurrentPage = PDFViewer.Document.PageCount;
- ((e as KeyEventArgs).OriginalSource as TextBox).Text = PDFViewer.Document.PageCount.ToString();
- return;
- }
- if (pagenum < 1)
- pagenum = 1;
- else if (pagenum > PDFViewer.Document.PageCount)
- pagenum = PDFViewer.Document.PageCount;
- PDFViewer.GoToPage(pagenum - 1);
- CurrentPage = pagenum;
- ((e as KeyEventArgs).OriginalSource as TextBox).Text = pagenum.ToString();
- }
- }
- private void GoPrePage()
- {
- if (PDFViewer != null)
- {
- if (PDFViewer.RenderPageStart == PDFViewer.CurrentIndex)
- {
- PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
- }
- else
- {
- if ((PDFViewer.RenderPageStart - 1) > 0)
- {
- PDFViewer.GoToPage(PDFViewer.RenderPageStart - 1);
- }
- else
- {
- PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
- }
- }
- }
- }
- private bool CanPrePageExcute()
- {
- if (PDFViewer != null)
- {
- if (PDFViewer.CurrentIndex <= 0)
- return false;
- else
- return true;
- }
- return false;
- }
- private void GoNextPage()
- {
- if (PDFViewer != null)
- {
- PDFViewer.GoToPage(PDFViewer.CurrentIndex + 1);
- //双页模式 一次性跳两页
- if (((int)PDFViewer.ModeView > 2))
- {
- PDFViewer.GoToPage(PDFViewer.CurrentIndex + 2);
- }
- }
- }
- private bool CanNextPageExcute()
- {
- if (PDFViewer != null)
- {
- if (CurrentPage >= PDFViewer.Document.PageCount)
- return false;
- else
- return true;
- }
- return false;
- }
- private void GoFirstPage()
- {
- if (PDFViewer != null)
- {
- PDFViewer.GoToPage(0);
- }
- }
- private void GoLastPage()
- {
- if (PDFViewer != null)
- {
- PDFViewer.GoToPage(PDFViewer.Document.PageCount - 1);
- }
- }
- private void ZoomIn()
- {
- double zoom = SetPageZoomFactor(true);
- PDFViewer.Zoom(zoom / 100);
- }
- private void ZoomOut()
- {
- double zoom = SetPageZoomFactor(false);
- PDFViewer.Zoom(zoom / 100);
- }
- private double SetPageZoomFactor(bool flag)
- {
- double zoom = PDFViewer.ZoomFactor * 100;
- if (flag)
- {
- if (zoom >= 25 && zoom <= 300)
- {
- zoom = zoom + 25;
- }
- else if (zoom >= 301 && zoom <= 1000)
- {
- zoom = zoom + 40;
- }
- else if (zoom >= 1001 && zoom <= 10000)
- {
- zoom = zoom + 100;
- }
- }
- else
- {
- if (zoom >= 25 && zoom <= 300)
- {
- zoom = zoom - 25;
- }
- else if (zoom >= 301 && zoom <= 1000)
- {
- zoom = zoom - 40;
- }
- else if (zoom >= 1001 && zoom <= 10000)
- {
- zoom = zoom - 100;
- }
- }
- if (zoom < 25)
- {
- zoom = 25;
- }
- if (zoom > 10000)
- {
- zoom = 10000;
- }
- return zoom;
- }
- private bool CanZoomIn()
- {
- if (PDFViewer != null)
- {
- if (PDFViewer.ZoomFactor * 100 >= 10000)
- return false;
- else
- return true;
- }
- return false;
- }
- private bool CanZoomOut()
- {
- if (PDFViewer != null)
- {
- if (PDFViewer.ZoomFactor * 100 <= 25)
- return false;
- else
- return true;
- }
- return false;
- }
- public void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
- {
- if (e.Key == "PageNum")
- {
- RenderData renderData = e.Value as RenderData;
- if (renderData != null)
- {
- CurrentPage = renderData.PageIndex;
- PageCount = PDFViewer.Document.PageCount;
- if (!renderData.IsMouseWheel && !isFromMethod)
- {
- UndoStack.Push(oldPageIndex);
- RedoStack.Clear();
- IsNextEnable = false;
- IsPreEnable = true;
- }
- isFromMethod = false;
- }
- oldPageIndex = renderData.PageIndex - 1;
- }
- if (e.Key == "ViewMode")
- {
- GetModeView((ViewMode)e.Value);
- }
- if (e.Key == "Zoom")
- {
- CurrentZoom = (double)e.Value * 100;
- switch (PDFViewer.ModeFit)
- {
- case FitMode.FitWidth:
- SelectedIndex = 1;
- break;
- case FitMode.FitHeight:
- SelectedIndex = 2;
- break;
- case FitMode.FitSize:
- SelectedIndex = 0;
- break;
- case FitMode.FitFree:
- SelectedIndex = -1;
- break;
- default:
- break;
- }
- }
- if (OpenFileInfo != null)
- {
- if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
- {
- OpenFileInfo.LastFitMode = PDFViewer.ModeFit;
- }
- if (PDFViewer.ModeFit == FitMode.FitFree)
- {
- if (OpenFileInfo.LastZoom != PDFViewer.ZoomFactor)
- {
- OpenFileInfo.LastZoom = PDFViewer.ZoomFactor;
- }
- }
- if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
- {
- OpenFileInfo.LastPageIndex = PDFViewer.CurrentIndex;
- }
- SettingHelper.SetFileInfo(OpenFileInfo);
- }
- }
- private void ViewContentViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- if (e.PropertyName == "OCRContentVisible")
- {
- if (ViewContentViewModel.OCRContentVisible == Visibility.Visible)
- {
- RightPanelEnable = false;
- }
- else
- {
- RightPanelEnable = true;
- }
- }
- if (e.PropertyName == "IsPropertyOpen")
- {
- //右上角按钮收起属性面板后,底部工具栏按钮状态同步变化
- if (ViewContentViewModel.IsPropertyOpen == false)
- {
- //监听的属性面板的变化
- IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
- }
- }
- }
- /// <summary>
- /// 设置缩放控件的选中项
- /// </summary>
- private void SetZoomIndex()
- {
- switch (PDFViewer.ModeFit)
- {
- case FitMode.FitWidth:
- SelectedIndex = 1;
- break;
- case FitMode.FitHeight:
- SelectedIndex = 2;
- break;
- case FitMode.FitSize:
- SelectedIndex = 0;
- break;
- case FitMode.FitFree:
- SelectedIndex = -1;
- break;
- default:
- break;
- }
- }
- private void GetModeView(ViewMode mode)
- {
- if ((int)mode % 2 == 0)
- {
- if (!IsContinue)
- {
- IsContinue = true;
- }
- }
- else
- {
- if (IsContinue)
- {
- IsContinue = false;
- }
- }
- if ((int)mode <= 2)
- {
- if (!isSingleView)
- {
- IsSingleView = true;
- }
- }
- else if ((int)mode <= 4)
- {
- if (!isDoubleView)
- {
- IsDoubleView = true;
- }
- }
- else
- {
- if (!isBookMode)
- {
- IsBookMode = true;
- }
- }
- }
- public void SetModeView()
- {
- if (PDFViewer != null)
- {
- if (IsContinue)
- {
- if (IsSingleView)
- {
- PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
- }
- else if (IsDoubleView)
- {
- PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
- }
- else
- {
- PDFViewer.ChangeViewMode(ViewMode.BookContinuous);
- }
- }
- else
- {
- if (IsSingleView)
- {
- PDFViewer.ChangeViewMode(ViewMode.Single);
- }
- else if (IsDoubleView)
- {
- PDFViewer.ChangeViewMode(ViewMode.Double);
- }
- else
- {
- PDFViewer.ChangeViewMode(ViewMode.Book);
- }
- }
- }
- SaveMode(PDFViewer.ModeView);
- }
- private void SaveMode(object modeView)
- {
- OpenFileInfo fileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
- if (fileInfo != null)
- {
- if (modeView is SplitMode)
- {
- fileInfo.LastSplitMode = PDFViewer.Mode;
- }
- else if (modeView is ViewMode)
- {
- fileInfo.LastViewMode = PDFViewer.ModeView;
- }
- else if (modeView is bool)
- {
- fileInfo.LastPageSpace = (bool)modeView;
- }
- SettingHelper.SetFileInfo(fileInfo);
- }
- }
- #region Navigation
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
- if (viewContentViewModel != null)
- {
- this.ViewContentViewModel = viewContentViewModel;
- ViewContentViewModel.bottom = this;
- IsShowViewModular = viewContentViewModel.IsPropertyOpen;
- viewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
- viewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
- }
- var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
- if (pdfview != null)
- {
- if (ViewContentViewModel.OpenFileInfo != null)
- {
- OpenFileInfo = ViewContentViewModel.OpenFileInfo;
- }
- //获取页面设置等信息
- PDFViewer = pdfview;
- PageCount = PDFViewer.Document.PageCount;
- //避免加密文档,刚进入文档时抛异常
- if (PageCount > 0)
- {
- oldPageIndex = pdfview.CurrentIndex;
- }
- GetModeView(PDFViewer.ModeView);
- //设置下拉框选中项
- SetZoomIndex();
- if (PageCount > 0)
- {
- //文档解密后再获取当前页,以此来确保上下翻页按钮的状态的准确的
- CurrentPage = PDFViewer.CurrentIndex + 1;
- }
- CurrentZoom = PDFViewer.ZoomFactor * 100;
- PDFViewer.InfoChanged += PDFViewer_InfoChanged;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
- }
- #endregion Navigation
- }
- }
|