123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using Microsoft.Win32;
- using PDF_Office.EventAggregators;
- using PDF_Office.Views;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Office.ViewModels
- {
- public enum LoadType
- {
- /// <summary>
- /// 打开文档
- /// </summary>
- Open,
- /// <summary>
- /// 创建文档
- /// </summary>
- Create
- }
- public class MainContentViewModel : BindableBase, INavigationAware
- {
- private string fileName = "Home";
- public string FileName
- {
- get { return fileName; }
- set { SetProperty(ref fileName, value); }
- }
- private string filePath;
- public string FilePath
- {
- get { return filePath; }
- set
- {
- SetProperty(ref filePath, value);
- if (!string.IsNullOrEmpty(filePath))
- {
- FileName = System.IO.Path.GetFileName(filePath);
- }
- }
- }
- private Visibility fileChanged;
- public Visibility FileChanged
- {
- get { return fileChanged; }
- set { SetProperty(ref fileChanged, value); }
- }
- public DelegateCommand<object> CloseTab { get; set; }
- private string regionName;
- public string RegionName
- {
- get { return regionName; }
- set { SetProperty(ref regionName, value); }
- }
- public IRegionManager toolregion;
- public IEventAggregator eventer;
- public IContainerProvider container;
- public MainContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IContainerProvider containerProvider)
- {
- toolregion = regionManager;
- eventer = eventAggregator;
- container = containerProvider;
- CloseTab = new DelegateCommand<object>(CloseTabItem);
- RegionName = Guid.NewGuid().ToString();
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- NavigationParameters parameters = new NavigationParameters
- {
- {
- "MainViewModel", this
- }
- };
- toolregion.RequestNavigate(RegionName, "HomeContent", parameters);
- }));
- }
- private void CloseTabItem(object item)
- {
- App.mainWindowViewModel?.CloseTabItem(item);
- App.OpenedFileList.Remove(FilePath);
- }
- public void OpenFile(string filePath)
- {
- FilePath = filePath;
- NavigationParameters parameters = new NavigationParameters { { "MainViewModel", this } };
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- toolregion.RequestNavigate(RegionName, "ViewContent", parameters);
- }));
-
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (navigationContext.Parameters.Count <= 0)
- return;
- var filepath = navigationContext.Parameters["filePath"];
- if(filepath!=null)
- {
- OpenFile(filepath.ToString());
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- if (navigationContext.Parameters.Count <= 0)
- return true;
- var isAddTab = navigationContext.Parameters["AddTab"];
- if (isAddTab!=null&&(bool)isAddTab)
- {
- return false;
- }
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- }
- }
|