123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using Microsoft.Win32;
- using PDF_Office.EventAggregators;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PDF_Office.ViewModels
- {
- public class HomeContentViewModel : BindableBase, INavigationAware
- {
- private string fileName = "Home";
- public string FileName
- {
- get { return fileName; }
- set { SetProperty(ref fileName, value); }
- }
- private string regionName;
- public string RegionName
- {
- get { return regionName; }
- set { SetProperty(ref regionName, value); }
- }
- private MainContentViewModel mainContentViewModel;
- public DelegateCommand OpenFileCommand { get; set; }
- public DelegateCommand<string> ShowToolCommand { get; set; }
- public IRegionManager toolregion;
- public IEventAggregator eventer;
- public HomeContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
- {
- toolregion = regionManager;
- eventer = eventAggregator;
- RegionName = Guid.NewGuid().ToString();
- OpenFileCommand = new DelegateCommand(OpenFile);
- ShowToolCommand = new DelegateCommand<string>(ShowToolContent);
- }
- /// <summary>
- /// 显示右侧不同的工具栏页面
- /// </summary>
- /// <param name="view"></param>
- public void ShowToolContent(string view)
- {
- toolregion.RequestNavigate(RegionName, view);
- }
- /// <summary>
- /// 打开文件
- /// </summary>
- public void OpenFile()
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- if (openFileDialog.FileNames.Count() == 1)
- {
- if (App.OpenedFileList.Contains(openFileDialog.FileName))
- {
- App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
- }
- else
- {
- mainContentViewModel.OpenFile(openFileDialog.FileName);
- }
- }
- else
- {
- var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
- if (fileList.Count <= 0)
- return;
- mainContentViewModel.OpenFile(fileList[0]);
- for (int i = 1; i < fileList.Count(); i++)
- {
- if (!App.OpenedFileList.Contains(fileList[i]))
- {
- App.mainWindowViewModel.AddTabItem(fileList[i]);
- }
- }
- }
- }
- }
- public void CreatBlankPDF()
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- var mainVM = navigationContext.Parameters["MainViewModel"] as MainContentViewModel;
- if (mainVM != null)
- {
- mainContentViewModel = mainVM;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- }
- }
|