using ComPDFKitViewer; using ComPDFKitViewer.PdfViewer; using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Properties; using PDF_Master.Views.PropertyPanel.ViewModular; using PDFSettings; using Prism.Commands; 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; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; using static PDF_Master.CustomControl.ColorDropBox; using RadioButton = System.Windows.Controls.RadioButton; namespace PDF_Master.ViewModels.PropertyPanel.ViewModular { public class ThemesContentViewModel : BindableBase, INavigationAware { public CPDFViewer PDFViewer { get; set; } public ViewModularContentViewModel ViewModularContentViewModel { get; set; } public Color? SelectedColor { get; set; } private bool resedaDrawMode; public bool ResedaDrawMode { get { return resedaDrawMode; } set { SetProperty(ref resedaDrawMode, value); if (value) { SetDrawModeEvent(null); } } } private bool darkDrawMode; public bool DarkDrawMode { get { return darkDrawMode; } set { SetProperty(ref darkDrawMode, value); if (value) { SetDrawModeEvent(null); } } } private bool sepiaDrawMode; public bool SepiaDrawMode { get { return sepiaDrawMode; } set { SetProperty(ref sepiaDrawMode, value); if (value) { SetDrawModeEvent(null); } } } private bool lightDrawMode; public bool LightDrawMode { get { return lightDrawMode; } set { SetProperty(ref lightDrawMode, value); if (value) { SetDrawModeEvent(null); } } } public DelegateCommand LoadedCommand { get; set; } public DelegateCommand SetDrawModeCommand { get; set; } public ThemesContentViewModel() { LoadedCommand = new DelegateCommand(LoadedEvent); SetDrawModeCommand = new DelegateCommand(SetDrawModeEvent); } private void LoadedEvent(object obj) { if (obj is WrapPanel wrapPanel) { InitBeforeShow(wrapPanel); } } /// /// 设置主题颜色 /// /// private void SetDrawModeEvent(object obj) { if (PDFViewer == null) { return; } SetUpDrawMode(PDFViewer, obj); if (ViewModularContentViewModel.SplitScreenPDFViewer != null) { SetUpDrawMode(ViewModularContentViewModel.SplitScreenPDFViewer, obj); } } private void SetUpDrawMode(CPDFViewer pDFViewer, object obj) { DrawModes draw = DrawModes.Draw_Mode_Normal; UInt32 color = 0; if (LightDrawMode) { draw = DrawModes.Draw_Mode_Normal; SetDrawMode(draw, color, pDFViewer); } else if (SepiaDrawMode) { draw = DrawModes.Draw_Mode_Soft; SetDrawMode(draw, color, pDFViewer); } else if (ResedaDrawMode) { draw = DrawModes.Draw_Mode_Green; SetDrawMode(draw, color, pDFViewer); } else if (DarkDrawMode) { draw = DrawModes.Draw_Mode_Dark; SetDrawMode(draw, color, pDFViewer); } else { if (obj is RadioButton radioButton) { draw = SetOtherThemeColors(radioButton, pDFViewer); } } //App.SplitScreenDrawModes = draw; } private DrawModes SetOtherThemeColors(RadioButton radioButton, CPDFViewer pDFViewer) { DrawModes draw = DrawModes.Draw_Mode_Normal; StackPanel panel = radioButton.Content as StackPanel; Rectangle rec = (panel.Children[0] as Border).Child as Rectangle; OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath); if (file != null) { file.LastFillBrushColor = ((SolidColorBrush)rec.Fill).Color; } var color1 = rec.Fill.ToString().Substring(1, 8); UInt32 c = Convert.ToUInt32(color1, 16); pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Normal); pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Custom, c); UpdateFileInfoList(DrawModes.Draw_Mode_Custom, c, pDFViewer); draw = DrawModes.Draw_Mode_Custom; //App.SplitScreenColor = c; return draw; } private void SetDrawMode(DrawModes drawMode, UInt32 color, CPDFViewer pDFViewer) { if (pDFViewer.GetDrawMode() != drawMode) { pDFViewer.SetDrawMode(drawMode); UpdateFileInfoList(drawMode, color, pDFViewer); } } /// /// 更新文件信息 /// /// /// private void UpdateFileInfoList(DrawModes modes, UInt32 color, CPDFViewer pDFViewer) { OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath); if (file != null) { file.LastDrawMode = modes; if (color != 0) { file.LastFillColor = color; } } SettingHelper.SetFileInfo(file); } /// /// 初始化后 /// /// private void InitBeforeShow(WrapPanel wrapPanel) { if (PDFViewer == null) { return; } var mode = PDFViewer.GetDrawMode(); if (mode == DrawModes.Draw_Mode_Normal) { LightDrawMode = true; } else if (mode == DrawModes.Draw_Mode_Dark) { DarkDrawMode = true; } else if (mode == DrawModes.Draw_Mode_Green) { ResedaDrawMode = true; } else if (mode == DrawModes.Draw_Mode_Soft) { SepiaDrawMode = true; } else { OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath); var color = info.LastFillBrushColor; for (int i = 4; i < wrapPanel.Children.Count; i++) { var btn = wrapPanel.Children[i] as RadioButton; if (btn != null && Color.Equals(((SolidColorBrush)(((btn.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill).Color, color)) { btn.IsChecked = true; } } } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { if (navigationContext.Parameters[ParameterNames.PDFViewer] is CPDFViewer pdfview) { PDFViewer = pdfview; } if (navigationContext.Parameters[ParameterNames.ViewModularContentViewModel] is ViewModularContentViewModel viewModularContentViewModel) { ViewModularContentViewModel = viewModularContentViewModel; } } } }