using ComPDFKitViewer.PdfViewer; using PDF_Office.EventAggregators; using PDF_Office.Model; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Windows; namespace PDF_Office.ViewModels.EditTools.Watermark { public class WatermarkContentViewModel : BindableBase,INavigationAware { public IEventAggregator eventAggregator; public IRegionManager watermarkRegion; private CPDFViewer PDFViewer; private ViewContentViewModel viewContentViewModel; public string TemplateListName = "WatermarkTemplateListBaseContent"; public string CreateName = "WatermarkCreateBaseContent"; public string CreateModTextName = "WatermarkCreateTextContent"; public string CreateModFileName = "WatermarkCreateFileContent"; public string TemplateListModTextName = "WatermarkTemplateListTextContent"; public string TemplateListModFileName = "WatermarkTemplateListFileContent"; public string WatermarkDocumentName = "WatermarkDocumentContent"; private string _watermarkSettingsRegionName; public string WatermarkSettingsRegionName { get { return _watermarkSettingsRegionName; } set { _watermarkSettingsRegionName = value; } } private Visibility _watermarkSettingsVisible = Visibility.Collapsed; public Visibility WatermarkSettingsVisible { get { return _watermarkSettingsVisible; } set { _watermarkSettingsVisible = value; } } private string _watermarkDocumentRegionName; /// /// 持有Document的Region,负责渲染和保存 /// public string WatermarkDocumentRegionName { get { return _watermarkDocumentRegionName; } set { _watermarkDocumentRegionName = value; } } private Visibility _watermarkDocumentVisible = Visibility.Visible; /// /// 持有Document的Region可见 /// public Visibility WatermarkDocumentVisible { get { return _watermarkDocumentVisible; } set { _watermarkDocumentVisible = value; } } private EnumTextOrFile _currentCreateMod; public EnumTextOrFile CurrentCreateMod { get { return _currentCreateMod; } set { _currentCreateMod = value; } } private EnumTextOrFile _currentTemplateListMod; public EnumTextOrFile CurrentTemplateListMod { get { return _currentTemplateListMod; } set { _currentTemplateListMod = value; } } public DelegateCommand CloseEditToolCommand { get; set; } public DelegateCommand ConfirmEditToolCommand { get; set; } public DelegateCommand EnterSelectedContentCommand { get; set; } public WatermarkContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; this.watermarkRegion = regionManager; WatermarkSettingsVisible = Visibility.Visible; WatermarkSettingsRegionName = Guid.NewGuid().ToString(); WatermarkDocumentRegionName = Guid.NewGuid().ToString(); CloseEditToolCommand = new DelegateCommand(CloseEditTool); ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool); EnterSelectedContentCommand = new DelegateCommand(EnterSelectedContent); eventAggregator.GetEvent().Subscribe(EnterTemplateListOrCreate); eventAggregator.GetEvent().Subscribe(SetCurrentCreateMod); eventAggregator.GetEvent().Subscribe(SetCurrentTemplateListMod); } public void CloseEditTool() { this.eventAggregator.GetEvent().Publish(); } public void ConfirmEditTool() { this.eventAggregator.GetEvent().Publish(CurrentCreateMod); } public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate) { if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate) { EnterSelectedContent(TemplateListName); } else { EnterSelectedContent(CreateName); } } public void SetCurrentCreateMod(string currentCreateModName) { if (currentCreateModName == CreateModTextName) { CurrentCreateMod = EnumTextOrFile.StatusText; } else if (currentCreateModName == CreateModFileName) { CurrentCreateMod = EnumTextOrFile.StatusFile; } } public void SetCurrentTemplateListMod(string currentTemplateListModName) { if (currentTemplateListModName == TemplateListModTextName) { CurrentTemplateListMod = EnumTextOrFile.StatusText; } else if (currentTemplateListModName == TemplateListModFileName) { CurrentTemplateListMod = EnumTextOrFile.StatusFile; } } public void EnterSelectedContent(string SelectedContentName) { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); if (SelectedContentName == TemplateListName) { param.Add("CurrentCreateModName", CurrentCreateMod); } else if (SelectedContentName == CreateName) { param.Add("CurrentTemplateListModName", CurrentTemplateListMod); } watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName, param); WatermarkSettingsVisible = Visibility.Visible; } public void EnterDocumentContent() { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); watermarkRegion.RequestNavigate(WatermarkDocumentRegionName, WatermarkDocumentName,param); WatermarkDocumentVisible = Visibility.Visible; } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); EnterSelectedContent(TemplateListName); EnterDocumentContent(); } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } } }