using ComPDFKitViewer; using ComPDFKitViewer.PdfViewer; using PDF_Master.EventAggregators; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.ViewModels; using PDF_Master.ViewModels.PropertyPanel.ViewModular; using PDF_Master.ViewModels.Tools; using PDF_Master.Views.Dialog; using PDF_Master.Views.PropertyPanel.ViewModular; using PDF_Master.Views.Tools; using Prism.Events; using Prism.Regions; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; namespace PDF_Master.Views { /// /// Interaction logic for ViewContent /// public partial class ViewContent : UserControl { private ViewContentViewModel viewModel = null; private string unicode = ""; public ViewContent() { InitializeComponent(); unicode = App.mainWindowViewModel.SelectedItem.Unicode; viewModel = (ViewContentViewModel)this.DataContext; viewModel.PropertyChanged += ViewModel_PropertyChanged; } private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "OpenBOTA") { if (!viewModel.OpenBOTA) { //动态改变BOTA的最小宽度只能在这里设置,VM里绑定会有异常 BOTACloumn.MinWidth = 48; viewModel.BOTAWidth = new GridLength(48); BOTASplitter.Visibility = Visibility.Collapsed; } else { BOTACloumn.MinWidth = 260; BOTASplitter.Visibility = Visibility.Visible; } } } public ViewContent(IEventAggregator eventAggregator) : this() { eventAggregator.GetEvent().Subscribe(ChangeSplitModeUI, e => e.Unicode == unicode); eventAggregator.GetEvent().Subscribe(ChangeReadModeUI, e => e.Unicode == unicode); eventAggregator.GetEvent().Subscribe(ChangeReadModePropertyOpenUI, e => e.Unicode == unicode); } private void ChangeReadModePropertyOpenUI(ReadModePropertyOpenArgs obj) { Grid.SetColumnSpan(GridViewer, 3); Grid.SetColumn(GridViewer, 0); Grid.SetColumn(Scroller, 4); } private void ChangeReadModeUI(ReadModeArgs obj) { if (obj.IsReadMode) { ReadModeContent.Visibility = Visibility.Visible; RectangleReadMode.Visibility = Visibility.Collapsed; this.TbtnProperty.IsChecked = false; Grid.SetRowSpan(DocumentView, 4); Grid.SetRow(DocumentView, 0); Grid.SetColumnSpan(GridViewer, 4); Grid.SetColumn(GridViewer, 0); } else { ReadModeContent.Visibility = Visibility.Collapsed; RectangleReadMode.Visibility = Visibility.Collapsed; //this.TbtnProperty.IsChecked=true; Grid.SetRowSpan(DocumentView, 1); Grid.SetRow(DocumentView, 2); Grid.SetColumnSpan(GridViewer, 1); Grid.SetColumn(GridViewer, 2); } } /// /// 鼠标移动到控件范围时显示控件 /// /// /// private void RectangleReadMode_MouseEnter(object sender, MouseEventArgs e) { //Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate //{ if (viewModel.mainViewModel.IsBookMode) { this.ReadModeContent.Visibility = Visibility.Visible; this.RectangleReadMode.Visibility = Visibility.Collapsed; } //})); } /// /// 鼠标移开页面控件,三秒后隐藏该控件 /// /// /// private async void ReadModeContent_MouseLeave(object sender, MouseEventArgs e) { await System.Threading.Tasks.Task.Delay(3000); //Thread.Sleep(3000); this.ReadModeContent.Visibility = Visibility.Collapsed; this.RectangleReadMode.Visibility = Visibility.Visible; } /// /// 根据Vm事件通知处理分屏布局的事件 /// /// private void ChangeSplitModeUI(SplitEventArgs e) { switch (e.Mode) { case EventAggregators.SplitMode.Horizontal: //水平分屏 上下 HorizontalSplitter.Visibility = Visibility.Visible; VerticalSplitter.Visibility = Visibility.Collapsed; RowRight.Height = new GridLength(1, GridUnitType.Star); ColumnBottom.Width = new GridLength(0); Grid.SetColumn(SplitPDFViewer, 0); Grid.SetRow(SplitPDFViewer, 2); break; case EventAggregators.SplitMode.Vertical: HorizontalSplitter.Visibility = Visibility.Collapsed; VerticalSplitter.Visibility = Visibility.Visible; RowRight.Height = new GridLength(0); ColumnBottom.Width = new GridLength(1, GridUnitType.Star); Grid.SetColumn(SplitPDFViewer, 2); Grid.SetRow(SplitPDFViewer, 0); break; case EventAggregators.SplitMode.Single: default: //退出分屏模式 HorizontalSplitter.Visibility = Visibility.Collapsed; VerticalSplitter.Visibility = Visibility.Collapsed; RowRight.Height = new GridLength(0, GridUnitType.Star); ColumnBottom.Width = new GridLength(0, GridUnitType.Star); break; } GridViewer.UpdateLayout(); } /// /// 退出阅读模式 /// /// /// private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (Key.Escape == e.Key) { if (viewModel != null) { if (viewModel.PDFViewer.MouseMode != MouseModes.PanTool) { if (this.ContentToolsBar.Content is AnnotToolContent annotTool) { if (annotTool.BtnSelecttool.IsChecked == true) { AnnotToolContentViewModel model = (AnnotToolContentViewModel)annotTool.DataContext; if (model != null) { if (model.SnapshotEditMenuViewModel.SnapToolArgs != null) { model.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot(); } } } } if (viewModel.mainViewModel.IsBookMode == true) { viewModel.Off_ReadModel(); } } else { if (viewModel.mainViewModel.IsBookMode == true) { viewModel.Off_ReadModel(); } } } } } private void BtnFile_Initialized(object sender, EventArgs e) { BtnFile.ContextMenu = null; } private void BtnFile_Click(object sender, RoutedEventArgs e) { FileMenu.PlacementTarget = BtnFile; FileMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; FileMenu.IsOpen = true; } private void ContentControl_SizeChanged(object sender, SizeChangedEventArgs e) { } private void MenuRecent_Loaded(object sender, RoutedEventArgs e) { int count = 0; MenuRecent.Items.Clear(); foreach (var file in Properties.Settings.Default.RecentOpenFiles) { MenuItem item = new MenuItem(); item.Height = 32; item.Header = file.FileName; item.Tag = file.FilePath; item.ToolTip = file.FilePath; item.Click += RecentItem_Click; MenuRecent.Items.Insert(MenuRecent.Items.Count, item); count++; if (count >= 20) break; } if (Properties.Settings.Default.RecentOpenFiles.Count > 0) { MenuRecent.Items.Add(Menu_Separator); MenuRecent.Items.Add(MenuDeleteAll); MenuDeleteAll.IsEnabled = true; MenuDeleteAll.Opacity = 1; } else { MenuRecent.Items.Add(MenuDeleteAll); MenuDeleteAll.IsEnabled = false; MenuDeleteAll.Opacity = 0.5; } } private void RecentItem_Click(object sender, RoutedEventArgs e) { var item = sender as MenuItem; string[] filePath = new string[1]; filePath[0] = item.Tag.ToString(); if (App.OpenedFileList.Contains(filePath[0])) { (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.SelectItem(filePath[0]); } else { (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.AddTabItem(filePath[0]); } } private void MenuDeleteAll_Click(object sender, RoutedEventArgs e) { SettingHelper.RemoveAllRecentOpenFiles(); } private void UserControl_DragEnter(object sender, DragEventArgs e) { DragDropHelper.DragEnter(this, e); } private void UserControl_DragOver(object sender, DragEventArgs e) { DragDropHelper.DragOver(this, e); } private void UserControl_DragLeave(object sender, DragEventArgs e) { DragDropHelper.DragLeave(); } private void UserControl_Drop(object sender, DragEventArgs e) { try { DragDropHelper.Drop(this, e); string[] file = (string[])e.Data.GetData(DataFormats.FileDrop); //页面编辑模式下 不响应拖拽打开文件 if (file != null && file.Length > 0 && !(this.DataContext as ViewContentViewModel).isInPageEdit) { App.mainWindowViewModel.AddTab.Execute(); (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).homeContentViewModel.AddFileFromDrag(file.ToList()); } } catch { } } private void CloseLeftCommand_Executed(object sender, ExecutedRoutedEventArgs e) { BOTASplitter.Visibility = Visibility.Collapsed; } private void CloseRightCommand_Executed(object sender, ExecutedRoutedEventArgs e) { viewModel.ClosePropertyCommand.Execute(); } } }