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.Controls; namespace PDF_Office.ViewModels.EditTools.Watermark { public class WatermarkCreateBaseContentViewModel : BindableBase, INavigationAware { IEventAggregator eventAggregator; IRegionManager watermarkCreateRegion; private CPDFViewer PDFViewer; public EnumTextOrFile CurrentTemplateListMod; private string watermarkCreateRegionName; public string WatermarkCreateRegionName { get => watermarkCreateRegionName; set => SetProperty(ref watermarkCreateRegionName, value); } private string _currentCreateName; public string CurrentCreateName { get => _currentCreateName; set => _currentCreateName = value; } private string _currentCreateModName; public string CurrentCreateModName { get => _currentCreateModName; set => _currentCreateModName = value; } private System.Windows.Visibility watermarkCreateVisible; public System.Windows.Visibility WatermarkCreateVisible { get => watermarkCreateVisible; set => SetProperty(ref watermarkCreateVisible, value); } public DelegateCommand ChangeCreateModCommand { get; set; } public DelegateCommand EnterTemplateListCommand { get; set; } public DelegateCommand SaveToTemplateListCommand { get; set; } public WatermarkCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; this.watermarkCreateRegion = regionManager; WatermarkCreateRegionName = Guid.NewGuid().ToString(); ChangeCreateModCommand = new DelegateCommand(ChangeCreateMod); EnterTemplateListCommand = new DelegateCommand(EnterTemplateList); SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList); } public void SaveToTemplateList() { if (CurrentCreateModName == "WatermarkCreateTextContent") { this.eventAggregator.GetEvent().Publish(EnumTextOrFile.StatusText); } if (CurrentCreateModName == "WatermarkCreateFileContent") { this.eventAggregator.GetEvent().Publish(EnumTextOrFile.StatusFile); } } public void EnterTemplateList() { this.eventAggregator.GetEvent().Publish(EnumTemplateListOrCreate.StatusTemplate); } public void EnterSelectedCreateMod(string currentCreateName) { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); watermarkCreateRegion.RequestNavigate(WatermarkCreateRegionName, currentCreateName, param); watermarkCreateVisible = System.Windows.Visibility.Visible; } public void ChangeCreateMod(object e) { var args = e as Button; if (args != null) { CurrentCreateName = args.Name; EnterSelectedCreateMod(CurrentCreateName); eventAggregator.GetEvent().Publish(CurrentCreateName); } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); navigationContext.Parameters.TryGetValue("CurrentTemplateListModName", out CurrentTemplateListMod); if (CurrentTemplateListMod == EnumTextOrFile.StatusText) { CurrentCreateModName = "WatermarkCreateTextContent"; } else { CurrentCreateModName = "WatermarkCreateFileContent"; } EnterSelectedCreateMod(CurrentCreateModName); eventAggregator.GetEvent().Publish(CurrentCreateModName); } } }