123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using Microsoft.Win32;
- using PDF_Office.CustomControl.SystemControl;
- using PDF_Office.Model;
- using PDF_Office.EventAggregators;
- using PDF_Office.Views;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using ComPDFKitViewer.PdfViewer;
- using Dragablz;
- using System.Windows;
- using Prism.Ioc;
- namespace PDF_Office.ViewModels
- {
- public class MainWindowViewModel : BindableBase
- {
- private MainContent selectedItem;
- public MainContent SelectedItem
- {
- get { return selectedItem; }
- set {
- SetProperty(ref selectedItem, value);
- if (SelectedItem!=null)
- {
- var pdfviewer = (SelectedItem.DataContext as MainContentViewModel).PDFViewer;
- if(pdfviewer!=null)
- {
- CurrentPDFViewer = pdfviewer;
- }
- }
- }
- }
- private CPDFViewer pdfViewer;
- /// <summary>
- /// 当前页签的PdfViewer对象
- /// </summary>
- public CPDFViewer CurrentPDFViewer
- {
- get { return pdfViewer; }
- set { pdfViewer = value; }
- }
- public DelegateCommand AddTab { get; set; }
- public IRegionManager region;
- public IEventAggregator eventer;
- private IContainerProvider containerProvider;
- public IInterTabClient InterTabClient { get; }
- public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IContainerProvider container)
- {
- if (App.mainWindowViewModel == null)
- {
- //加载第一个窗体时 先赋值静态对象
- App.mainWindowViewModel = this;
- }
- region = regionManager;
- eventer = eventAggregator;
- containerProvider = container;
- InterTabClient = new InterTabClient(container);
- AddTab = new DelegateCommand(AddTabItem);
- //第一次打开时需要自动加载Home页
- if (App.IsFirstOpen)
- {
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- region.RequestNavigate(RegionNames.MainRegion, "MainContent");
- }
- ));
- App.IsFirstOpen = false;
- }
- }
- /// <summary>
- /// 单击+号时添加页签
- /// </summary>
- private void AddTabItem()
- {
- region.RequestNavigate(RegionNames.MainRegion, "MainContent");
- }
- /// <summary>
- /// 选择多文档打开时
- /// </summary>
- /// <param name="filePath"></param>
- public void AddTabItem(string filePath)
- {
- NavigationParameters parameters = new NavigationParameters
- {
- { ParameterNames.FilePath, filePath }
- };
- region.RequestNavigate(RegionNames.MainRegion, "MainContent", parameters);
- }
- public void CloseTabItem(object item)
- {
- if (region.Regions[RegionNames.MainRegion].Views.Count() > 1)
- {
- region.Regions[RegionNames.MainRegion].Remove(item);
- }
- else
- {
- App.Current.MainWindow.Close();
- }
- return;
- }
- public void SelectItem(string filepath)
- {
- var item = region.Regions[RegionNames.MainRegion].Views.Where(t => ((t as MainContent).DataContext as MainContentViewModel).FilePath == filepath).FirstOrDefault() as MainContent;
- if (item == null)
- return;
- region.Regions[RegionNames.MainRegion].Activate(item);
- var behavior = region.Regions[RegionNames.MainRegion].Behaviors[DragablzWindowBehavior.BehaviorKey] as DragablzWindowBehavior;
- if(behavior!=null)
- {
- behavior.ActivateView(item);
- }
- }
- }
- }
|