|
@@ -19,6 +19,8 @@ using System.Windows.Media;
|
|
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
|
|
using TextBox = System.Windows.Controls.TextBox;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
+using Button = System.Windows.Controls.Button;
|
|
|
+using System.Windows.Controls.Primitives;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
{
|
|
@@ -49,12 +51,42 @@ namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private bool CanNextPageExcute()
|
|
|
+ {
|
|
|
+ if (PDFViewer != null)
|
|
|
+ {
|
|
|
+ if (PDFViewer.CurrentIndex >= PDFViewer.Document.PageCount - 1)
|
|
|
+ return false;
|
|
|
+ else
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CanPrePageExcute()
|
|
|
+ {
|
|
|
+ if (PDFViewer != null)
|
|
|
+ {
|
|
|
+ if (PDFViewer.CurrentIndex <= 0)
|
|
|
+ return false;
|
|
|
+ else
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Button btnPrePage = null;
|
|
|
+ private Button btnNextPage = null;
|
|
|
+ private RepeatButton btnZoomOut = null;
|
|
|
+ private RepeatButton btnZoomIn = null;
|
|
|
+
|
|
|
public DelegateCommand<object> KeyDownCommand { get; set; }
|
|
|
public DelegateCommand<object> PreviewKeyDownCommand { get; set; }
|
|
|
public DelegateCommand<object> ZoomOutCommand { get; set; }
|
|
|
public DelegateCommand<object> ZoomInCommand { get; set; }
|
|
|
- public DelegateCommand<object> PrePageCommand { get; set; }
|
|
|
- public DelegateCommand<object> NextPageCommand { get; set; }
|
|
|
+ public DelegateCommand PrePageCommand { get; set; }
|
|
|
+ public DelegateCommand NextPageCommand { get; set; }
|
|
|
+ public DelegateCommand<object> LoadedCommand { get; set; }
|
|
|
|
|
|
public ReadModeContentViewModel()
|
|
|
{
|
|
@@ -63,60 +95,149 @@ namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
ZoomOutCommand = new DelegateCommand<object>(PageZoomOutEvent);
|
|
|
ZoomInCommand = new DelegateCommand<object>(PageZoomInEvent);
|
|
|
|
|
|
- PrePageCommand = new DelegateCommand<object>(PrePageEvent);
|
|
|
- NextPageCommand = new DelegateCommand<object>(NextPageEvent);
|
|
|
+ PrePageCommand = new DelegateCommand(PrePageEvent);
|
|
|
+ NextPageCommand = new DelegateCommand(NextPageEvent);
|
|
|
+ LoadedCommand = new DelegateCommand<object>(Loaded);
|
|
|
}
|
|
|
|
|
|
- private void NextPageEvent(object obj)
|
|
|
+ /// <summary>
|
|
|
+ /// 页面加载
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void Loaded(object obj)
|
|
|
{
|
|
|
- if (PDFViewer.ModeView == ComPDFKitViewer.ViewMode.Double || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.DoubleContinuous || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.Book || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.BookContinuous)
|
|
|
-
|
|
|
+ if (obj is CompositeCommandParameter composite)
|
|
|
{
|
|
|
- PDFViewer.GoToPage(PDFViewer.CurrentIndex + 2);
|
|
|
+ if (composite.Parameter is object[] array)
|
|
|
+ {
|
|
|
+ btnPrePage = array[0] as Button;
|
|
|
+ btnNextPage = array[1] as Button;
|
|
|
+ btnZoomOut = array[2] as RepeatButton;
|
|
|
+ btnZoomIn = array[3] as RepeatButton;
|
|
|
+ ChangeBtnZoom();
|
|
|
+ ChangePageBtnState();
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- PDFViewer.GoToPage(PDFViewer.CurrentIndex + 1);
|
|
|
}
|
|
|
|
|
|
- private void PrePageEvent(object obj)
|
|
|
+ /// <summary>
|
|
|
+ /// 下一页
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void NextPageEvent()
|
|
|
{
|
|
|
if (PDFViewer.ModeView == ComPDFKitViewer.ViewMode.Double || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.DoubleContinuous || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.Book || PDFViewer.ModeView == ComPDFKitViewer.ViewMode.BookContinuous)
|
|
|
+
|
|
|
{
|
|
|
- PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
|
|
|
+ if (((int)PDFViewer.Mode % 2) == 0)
|
|
|
+ {
|
|
|
+ PDFViewer.GoToPage(PDFViewer.CurrentIndex + 2);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
|
|
|
+ PDFViewer.GoToPage(PDFViewer.CurrentIndex + 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 上一页
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void PrePageEvent()
|
|
|
+ {
|
|
|
+ PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 放大
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void PageZoomInEvent(object obj)
|
|
|
{
|
|
|
- double zoom = PDFViewer.ZoomFactor * 100;
|
|
|
- zoom = zoom + 25;
|
|
|
- if (zoom != 0 && zoom <= 1000 && PDFViewer != null)
|
|
|
+ if (PDFViewer != null)
|
|
|
{
|
|
|
+ double zoom = SetPageZoomFactor(true);
|
|
|
PDFViewer.Zoom(zoom / 100);
|
|
|
+ ChangeBtnZoom();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void PageZoomOutEvent(object obj)
|
|
|
+ /// <summary>
|
|
|
+ /// 设置缩放因子
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="flag"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private double SetPageZoomFactor(bool flag)
|
|
|
{
|
|
|
double zoom = PDFViewer.ZoomFactor * 100;
|
|
|
- zoom = zoom - 25;
|
|
|
- if (zoom != 0 && PDFViewer != null)
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 缩小
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void PageZoomOutEvent(object obj)
|
|
|
+ {
|
|
|
+ if (PDFViewer != null)
|
|
|
{
|
|
|
+ double zoom = SetPageZoomFactor(false);
|
|
|
PDFViewer.Zoom(zoom / 100);
|
|
|
+ ChangeBtnZoom();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 输入限制
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void PreviewKeyDownEvent(object obj)
|
|
|
{
|
|
|
var args = obj 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};
|
|
|
+ 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;
|
|
@@ -124,6 +245,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 回车键保存
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void KeyDownEvent(object obj)
|
|
|
{
|
|
|
if (obj is CompositeCommandParameter objs)
|
|
@@ -160,9 +285,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
|
|
|
PDFViewer.GoToPage(pagenum - 1);
|
|
|
CurrentPage = pagenum;
|
|
|
- txtCurrentPageNum.Text = pagenum.ToString();
|
|
|
+
|
|
|
textBlock.Visibility = System.Windows.Visibility.Visible;
|
|
|
+
|
|
|
+ txtCurrentPageNum.Text = pagenum.ToString();
|
|
|
txtCurrentPageNum.Background = new SolidColorBrush(Colors.Transparent);
|
|
|
+ //移动焦点
|
|
|
txtCurrentPageNum.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
|
|
|
}
|
|
|
}
|
|
@@ -181,30 +309,115 @@ namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
|
|
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
{
|
|
|
- var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
|
|
|
- if (viewContentViewModel != null)
|
|
|
+ if (navigationContext.Parameters[ParameterNames.ViewContentViewModel] is ViewContentViewModel viewContentViewModel)
|
|
|
{
|
|
|
this.viewContentViewModel = viewContentViewModel;
|
|
|
}
|
|
|
- var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
|
|
|
- if (pdfview != null)
|
|
|
+ if (navigationContext.Parameters[ParameterNames.PDFViewer] is CPDFViewer pdfview)
|
|
|
{
|
|
|
//获取页面设置等信息
|
|
|
this.PDFViewer = pdfview;
|
|
|
- PageCount = PDFViewer.Document.PageCount;
|
|
|
- CurrentPage = PDFViewer.CurrentIndex + 1;
|
|
|
- this.PDFViewer.InfoChanged += PDFViewer_InfoChanged;
|
|
|
+ if (PDFViewer != null)
|
|
|
+ {
|
|
|
+ PageCount = PDFViewer.Document.PageCount;
|
|
|
+ CurrentPage = PDFViewer.CurrentIndex + 1;
|
|
|
+ this.PDFViewer.InfoChanged += PDFViewer_InfoChanged;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 滚动的时候,参数变化
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
private void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
{
|
|
|
if (e.Key == "SplieMode" || e.Key == "ViewMode")
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- PageCount = PDFViewer.Document.PageCount;
|
|
|
- CurrentPage = PDFViewer.CurrentIndex + 1;
|
|
|
+ if (e.Key == "PageNum")
|
|
|
+ {
|
|
|
+ CurrentPage = (int)e.Value;
|
|
|
+ PageCount = PDFViewer.Document.PageCount;
|
|
|
+ ChangeBtnZoom();
|
|
|
+ ChangePageBtnState();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 改变缩放按钮
|
|
|
+ /// </summary>
|
|
|
+ private void ChangeBtnZoom()
|
|
|
+ {
|
|
|
+ if (PDFViewer == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (btnZoomOut == null && btnZoomIn == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (PDFViewer.ZoomFactor * 100 <= 25)
|
|
|
+ {
|
|
|
+ btnZoomOut.IsEnabled = false;
|
|
|
+ btnZoomOut.Opacity = 0.5;
|
|
|
+
|
|
|
+ btnZoomIn.IsEnabled = true;
|
|
|
+ btnZoomIn.Opacity = 1;
|
|
|
+ }
|
|
|
+ else if (PDFViewer.ZoomFactor * 100 >= 25 && PDFViewer.ZoomFactor * 100 <= 10000)
|
|
|
+ {
|
|
|
+ btnZoomOut.Opacity = 1;
|
|
|
+ btnZoomOut.IsEnabled = true;
|
|
|
+
|
|
|
+ btnZoomIn.IsEnabled = true;
|
|
|
+ btnZoomIn.Opacity = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ btnZoomIn.IsEnabled = false;
|
|
|
+ btnZoomIn.Opacity = 0.5;
|
|
|
+
|
|
|
+ btnZoomOut.IsEnabled = true;
|
|
|
+ btnZoomOut.Opacity = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 改变上一页、下一页按钮
|
|
|
+ /// </summary>
|
|
|
+ private void ChangePageBtnState()
|
|
|
+ {
|
|
|
+ if (PDFViewer == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (btnPrePage == null && btnNextPage == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (PDFViewer.CurrentIndex + 1 <= 1)
|
|
|
+ {
|
|
|
+ btnPrePage.IsEnabled = false;
|
|
|
+ btnPrePage.Opacity = 0.5;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ btnPrePage.IsEnabled = true;
|
|
|
+ btnPrePage.Opacity = 1;
|
|
|
+ }
|
|
|
+ if (PDFViewer.CurrentIndex + 1 >= PDFViewer.Document.PageCount)
|
|
|
+ {
|
|
|
+ btnNextPage.IsEnabled = false;
|
|
|
+ btnNextPage.Opacity = 0.5;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ btnNextPage.IsEnabled = true;
|
|
|
+ btnNextPage.Opacity = 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|