using Dropbox.Api.Sharing; using PDF_Office.EventAggregators; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; using System.Windows; using System.Linq; using System.Windows.Controls; using Visibility = System.Windows.Visibility; using Dropbox.Api.FileProperties; using ComPDFKitViewer.PdfViewer; using PDF_Office.Model; namespace PDF_Office.ViewModels.EditTools.Background { public class BackgroundContentViewModel : BindableBase, INavigationAware { public IEventAggregator eventAggregator; public IRegionManager backgroundRegion; private CPDFViewer PDFViewer; private ViewContentViewModel viewContentViewModel; public string TemplateListName = "BackgroundTemplateListBaseContent"; public string CreateName = "BackgroundCreateBaseContent"; public string CreateModColorName = "BackgroundCreateColorContent"; public string CreateModFileName = "BackgroundCreateFileContent"; public string TemplateListModColorName = "BackgroundTemplateListColorContent"; public string TemplateListModFileName = "BackgroundTemplateListFileContent"; public string BackgroundDocumentName = "BackgroundDocumentContent"; private string _backgroundSettingsRegionName; /// /// 属性设置Region /// public string BackgroundSettingsRegionName { get { return _backgroundSettingsRegionName; } set { _backgroundSettingsRegionName = value; } } private Visibility _backgroundSettingsVisible = Visibility.Collapsed; /// /// 属性设置Region可见 /// public Visibility BackgroundSettingsVisible { get { return _backgroundSettingsVisible; } set { _backgroundSettingsVisible = value; } } private string _backgroundDocumentRegionName; /// /// 持有Document的Region,负责渲染和保存 /// public string BackgroundDocumentRegionName { get { return _backgroundDocumentRegionName; } set { _backgroundDocumentRegionName = value; } } private Visibility _backgroundDocumentVisible = Visibility.Visible; /// /// 持有Document的Region可见 /// public Visibility BackgroundDocumentVisible { get { return _backgroundDocumentVisible; } set { _backgroundDocumentVisible = value; } } private EnumColorOrFile _currentCreateMod; public EnumColorOrFile CurrentCreateMod { get { return _currentCreateMod; } set { _currentCreateMod = value; } } private EnumColorOrFile _currentTemplateListMod; public EnumColorOrFile CurrentTemplateListMod { get { return _currentTemplateListMod; } set { _currentTemplateListMod = value; } } /// /// 退出EditTool /// public DelegateCommand CloseEditToolCommand { get; set; } public DelegateCommand ConfirmEditToolCommand { get; set; } public DelegateCommand EnterSelectedContentCommand { get; set; } public BackgroundContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; this.backgroundRegion = regionManager; BackgroundSettingsVisible = Visibility.Visible; BackgroundSettingsRegionName = Guid.NewGuid().ToString(); BackgroundDocumentRegionName = 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 == CreateModColorName) { CurrentCreateMod = EnumColorOrFile.StatusColor; } else if (currentCreateModName == CreateModFileName) { CurrentCreateMod = EnumColorOrFile.StatusFile; } } public void SetCurrentTemplateListMod(string currentTemplateListModName) { if (currentTemplateListModName == TemplateListModColorName) { CurrentTemplateListMod = EnumColorOrFile.StatusColor; } else if (currentTemplateListModName == TemplateListModFileName) { CurrentTemplateListMod = EnumColorOrFile.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); } backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param); BackgroundSettingsVisible = Visibility.Visible; } public void EnterDocumentContent() { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param); BackgroundDocumentVisible = 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) { } } }