using ComPDFKit.PDFDocument; using ComPDFKitViewer.PdfViewer; using ImTools; using PDF_Office.Helper; using PDF_Office.Model; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using static Dropbox.Api.TeamLog.AdminAlertSeverityEnum; using static System.Net.Mime.MediaTypeNames; namespace PDF_Office.ViewModels.BOTA { public class BookmarkContentViewModel : BindableBase, INavigationAware { #region 属性 private static string hoverColor = "#D9D9D9"; private static string defaultColor = "#F2F2F2"; private static string selectColcr = "#97D7FB"; private static string borderBackground = "#FFFFFF"; private static string borderBrush = "#000000"; private IRegionManager region; private IDialogService dialogs; public CPDFViewer PDFViewer; //public ObservableCollection Bookmarklist { get; set; } private ObservableCollection list; private ObservableCollection bookmarklist; public ObservableCollection Bookmarklist { get { return bookmarklist; } set { SetProperty(ref bookmarklist, value); } } private Visibility isEmpty; public Visibility IsEmptyPanelVisibility { get { return isEmpty; } set { SetProperty(ref isEmpty, value); } } #endregion 属性 #region 命令 public DelegateCommand MouseClickCommand { get; set; } public DelegateCommand MouseEnterCommand { get; set; } public DelegateCommand MouseMoveCommand { get; set; } public DelegateCommand LostFocusCommand { get; set; } public DelegateCommand GotFocusCommand { get; set; } public DelegateCommand AddBookmarkCommand { get; set; } #endregion 命令 public BookmarkContentViewModel(IRegionManager regionManager, IDialogService dialogService) { region = regionManager; dialogs = dialogService; MouseClickCommand = new DelegateCommand(MouseClickEvent); MouseEnterCommand = new DelegateCommand(MouseEnterEvent); LostFocusCommand = new DelegateCommand(LostFocusEvent); MouseMoveCommand = new DelegateCommand(MouseMoveEvent); GotFocusCommand = new DelegateCommand(GotFocusEvent); AddBookmarkCommand = new DelegateCommand(AddBookmarkEvent); } private void AddBookmarkEvent(object obj) { int index = PDFViewer.CurrentIndex; string mark = string.Format($"第{index}页"); } private void GotFocusEvent(object obj) { if (obj is RoutedEventArgs) { var mouse = (RoutedEventArgs)obj; if (mouse.Source is TextBox) { TextBox textBox = (TextBox)mouse.Source; textBox.Select(textBox.Text.Length, 0); textBox.SelectAll(); } } } private void MouseMoveEvent(object obj) { //if (obj is MouseEventArgs) //{ // var mouse = (MouseEventArgs)obj; // Grid grid = null; // if (mouse.Source is TextBox) // { // TextBox text = (TextBox)mouse.Source; // if (text != null) // { // text.Visibility = Visibility.Collapsed; // grid = (text.Parent as StackPanel).Parent as Grid; // grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor)); // } // } //} } private void LostFocusEvent(object obj) { if (obj is RoutedEventArgs) { var mouse = (RoutedEventArgs)obj; Grid grid = null; if (mouse.Source is Grid) { grid = mouse.Source as Grid; if (grid != null) { TextBlock box = CommonHelper.FindVisualChild(grid); if (box != null) { box.Visibility = Visibility.Visible; } grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor)); } } if (mouse.Source is TextBox) { TextBox textBox = (TextBox)mouse.Source; if (textBox != null) { //textBox.Visibility = Visibility.Collapsed; grid = (textBox.Parent as StackPanel).Parent as Grid; grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(defaultColor)); } } } } public void MouseEnterEvent(object obj) { if (obj is MouseEventArgs) { var mouse = (MouseEventArgs)obj; Grid grid = null; if (mouse.Source is Grid) { grid = mouse.Source as Grid; if (grid != null) { TextBlock box = CommonHelper.FindVisualChild(grid); if (box != null) { //box.Visibility = Visibility.Visible; } grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor)); } } if (mouse.Source is TextBlock) { TextBlock text = (TextBlock)mouse.Source; if (text != null) { //text.Visibility = Visibility.Visible; grid = (text.Parent as StackPanel).Parent as Grid; grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor)); } } //if (mouse.Source is TextBox) //{ // TextBox text = (TextBox)mouse.Source; // if (text != null) // { // text.Visibility = Visibility.Collapsed; // grid = (text.Parent as StackPanel).Parent as Grid; // grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hoverColor)); // } //} } else { } } public void MouseClickEvent(object obj) { if (obj is MouseButtonEventArgs) { var mouse = (MouseButtonEventArgs)obj; if (mouse.LeftButton == MouseButtonState.Pressed) { TextBlock box = null; Grid grid = null; if (mouse.ClickCount >= 2) { if (mouse.Source is Grid) { grid = mouse.Source as Grid; //grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr)); if (grid != null) { box = CommonHelper.FindVisualChild(grid); grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr)); if (box != null) { box.Visibility = Visibility.Collapsed; //TextBox textBox = CommonHelper.FindVisualChild((box.Parent as StackPanel)); //FocusManager.SetFocusedElement(box.Parent, textBox); //Keyboard.Focus(textBox); //textBox.IsHitTestVisible = true; //textBox.Focus(); } } } if (mouse.Source is TextBlock) { box = (TextBlock)mouse.Source; grid = (box.Parent as StackPanel).Parent as Grid; grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(selectColcr)); if (box != null) { box.Visibility = Visibility.Collapsed; //TextBox textBox = CommonHelper.FindVisualChild((box.Parent as StackPanel)); //FocusManager.SetFocusedElement(box.Parent, textBox); //Keyboard.Focus(textBox); //textBox.IsHitTestVisible = true; //textBox.Focus(); } } } //MessageBox.Show("dsafa"); } } } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); if (PDFViewer == null) { return; } Bookmarklist = new ObservableCollection(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title)); if (Bookmarklist.Count < 1) { IsEmptyPanelVisibility = Visibility.Visible; return; } else { IsEmptyPanelVisibility = Visibility.Hidden; return; } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } } }