123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Office.Interop.PowerPoint;
- using PDF_Office.CustomControl;
- using PDF_Office.Helper;
- using PDF_Office.Properties;
- using PDF_Office.ViewModels.PropertyPanel.ViewModular;
- using PDFSettings.Settings;
- 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.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using static PDF_Office.CustomControl.ColorDropBox;
- namespace PDF_Office.Views.PropertyPanel.ViewModular
- {
- /// <summary>
- /// ThemesContent.xaml 的交互逻辑
- /// </summary>
- public partial class ThemesContent : UserControl
- {
- private ThemesContentViewModel viewModel = null;
- private ColorDropBoxPop colorPop = new ColorDropBoxPop();
- private AdornerLayer popLayer;
- private AdornerPresenter layerPresent;
- private Canvas popCanvas;
- public Color? SelectedColor { get; set; }
- public ThemesContent()
- {
- InitializeComponent();
- InitBeforeShow();
- }
- /// <summary>
- /// 设置自定义主题显示状态
- /// </summary>
- public void InitBeforeShow()
- {
- if (Settings.Default.AppProperties.CustomColorList != null && Settings.Default.AppProperties.CustomColorList.Count > 0)
- {
- var list = Settings.Default.AppProperties.CustomColorList;
- switch (list.Count)
- {
- case 1:
- (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
- RBtnThemes1.Visibility = Visibility.Visible;
- break;
- case 2:
- (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
- (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
- RBtnThemes1.Visibility = Visibility.Visible;
- RBtnThemes2.Visibility = Visibility.Visible;
- break;
- case 3:
- (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
- (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
- (((RBtnThemes3.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[2]);
- RBtnThemes1.Visibility = Visibility.Visible;
- RBtnThemes2.Visibility = Visibility.Visible;
- RBtnThemes3.Visibility = Visibility.Visible;
- break;
- case 4:
- (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
- (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
- (((RBtnThemes3.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[2]);
- (((RBtnThemes4.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[3]);
- RBtnThemes1.Visibility = Visibility.Visible;
- RBtnThemes2.Visibility = Visibility.Visible;
- RBtnThemes3.Visibility = Visibility.Visible;
- RBtnThemes4.Visibility = Visibility.Visible;
- break;
- }
- }
- }
- /// <summary>
- /// 页面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- if (popLayer == null)
- {
- Window parentWnd = Window.GetWindow(this);
- if (parentWnd != null && parentWnd.Content is UIElement)
- {
- popLayer = AdornerLayer.GetAdornerLayer(parentWnd.Content as UIElement);
- if (popLayer != null && colorPop != null)
- {
- layerPresent = new AdornerPresenter(popLayer);
- popLayer.Add(layerPresent);
- colorPop.Visibility = Visibility.Collapsed;
- colorPop.ColorSelected += ColorPop_ColorSelected;
- popCanvas = new Canvas();
- popCanvas.Children.Add(colorPop);
- layerPresent.VisualContent = popCanvas;
- parentWnd.AddHandler(MouseDownEvent, new MouseButtonEventHandler((eventsender, param) =>
- {
- colorPop.Visibility = Visibility.Collapsed;
- }), false);
- }
- }
- }
- viewModel = (ThemesContentViewModel)this.DataContext;
- }
- /// <summary>
- /// 自定义主题颜色,选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ColorPop_ColorSelected(object sender, Color e)
- {
- if (RBtnThemes1.Visibility == Visibility.Collapsed)
- {
- RBtnThemes1.Visibility = Visibility.Visible;
- var panel = RBtnThemes1.Content as StackPanel;
- var rec = (panel.Children[0] as Border).Child as Rectangle;
- rec.Fill = new SolidColorBrush(e);
- Settings.Default.AppProperties.CustomColorList.Add(e);
- }
- else if (RBtnThemes2.Visibility == Visibility.Collapsed)
- {
- RBtnThemes2.Visibility = Visibility.Visible;
- var panel = RBtnThemes2.Content as StackPanel;
- var rec = (panel.Children[0] as Border).Child as Rectangle;
- rec.Fill = new SolidColorBrush(e);
- Settings.Default.AppProperties.CustomColorList.Add(e);
- }
- else if (RBtnThemes3.Visibility == Visibility.Collapsed)
- {
- RBtnThemes3.Visibility = Visibility.Visible;
- var panel = RBtnThemes3.Content as StackPanel;
- var rec = (panel.Children[0] as Border).Child as Rectangle;
- rec.Fill = new SolidColorBrush(e);
- Settings.Default.AppProperties.CustomColorList.Add(e);
- }
- else if (RBtnThemes4.Visibility == Visibility.Collapsed)
- {
- RBtnThemes4.Visibility = Visibility.Visible;
- var panel = RBtnThemes4.Content as StackPanel;
- var rec = (panel.Children[0] as Border).Child as Rectangle;
- rec.Fill = new SolidColorBrush(e);
- Settings.Default.AppProperties.CustomColorList.Add(e);
- }
- #region to do
- //if(Settings.Default.AppProperties.CustomColorList.Count>4)
- //{
- // for(int i=4;i< Settings.Default.AppProperties.CustomColorList.Count;i++)
- // {
- // Settings.Default.AppProperties.CustomColorList.RemoveAt(i);
- // }
- //}
- #endregion to do
- Settings.Default.Save();
- if (SelectedColor != e)
- {
- SelectedColor = e;
- colorPop.AddColorToRecent(e);
- }
- }
- /// <summary>
- /// 自定义颜色显示状态发生变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RBtnThemes1_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (RBtnThemes1.Visibility == Visibility.Visible &&
- RBtnThemes2.Visibility == Visibility.Visible &&
- RBtnThemes3.Visibility == Visibility.Visible &&
- RBtnThemes4.Visibility == Visibility.Visible)
- {
- RBtnCustom.Visibility = Visibility.Collapsed;
- }
- else
- {
- RBtnCustom.Visibility = Visibility.Visible;
- }
- }
- /// <summary>
- /// 添加自定义主题颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RBtnCustom_Click(object sender, RoutedEventArgs e)
- {
- if (colorPop != null)
- {
- if (colorPop.Visibility == Visibility.Visible)
- {
- colorPop.Visibility = Visibility.Collapsed;
- return;
- }
- colorPop.Visibility = Visibility.Visible;
- System.Windows.Point offset = GetOffsetToWindow();
- Window parentWnd = Window.GetWindow(this);
- colorPop.Measure(new Size(parentWnd.ActualWidth, parentWnd.ActualHeight));
- colorPop.SetValue(Canvas.TopProperty, offset.Y - colorPop.DesiredSize.Height / 4);
- if (offset.X + colorPop.DesiredSize.Width + SystemParameters.ResizeFrameVerticalBorderWidth * 2 > parentWnd.ActualWidth)
- {
- colorPop.SetValue(Canvas.LeftProperty, parentWnd.ActualWidth - colorPop.DesiredSize.Width - 5 - SystemParameters.ResizeFrameVerticalBorderWidth * 2);
- }
- else
- {
- colorPop.SetValue(Canvas.LeftProperty, offset.X - colorPop.DesiredSize.Width / 2 - 30);
- }
- colorPop.AddColorToRecent((Color)ColorConverter.ConvertFromString("White")); ;
- }
- }
- public System.Windows.Point GetOffsetToWindow()
- {
- Window parentWnd = Window.GetWindow(this);
- return TransformToAncestor(parentWnd).Transform(new System.Windows.Point(0, 0));
- }
- /// <summary>
- /// 删除自定义颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
- var contextmenu = (sender as MenuItem).Parent as ContextMenu;
- if (contextmenu != null)
- {
- RadioButton btn = contextmenu.PlacementTarget as RadioButton;
- btn.Visibility = Visibility.Collapsed;
- if (btn.IsChecked == true)
- {
- //如果删除了选中色 则更换主题为白色
- RBtnLight.IsChecked = true;
- }
- var color = (((btn.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill;
- if (Settings.Default.AppProperties.CustomColorList.Contains(((SolidColorBrush)color).Color))
- {
- Settings.Default.AppProperties.CustomColorList.Remove(((SolidColorBrush)color).Color);
- Settings.Default.Save();
- }
- }
- }
- private void RBtnDark_Click(object sender, RoutedEventArgs e)
- {
- if (Window.GetWindow(this) is MainWindow window)
- {
- if (window.TabablzControl.SelectedItem is MainContent main)
- {
- if (main.ContentMain.Content is ViewContent viewContent)
- {
- foreach (var item in viewContent.GridViewer.Children)
- {
- if (item is ContentControl control)
- {
- if (control.Content is SplitScreenContent splitScreenContent)
- {
- if (splitScreenContent.PDFViewerContent.Content != null)
- {
- viewModel.ViewModularContentViewModel.SplitScreenPDFViewer = (ComPDFKitViewer.PdfViewer.CPDFViewer)splitScreenContent.PDFViewerContent.Content;
- break;
- }
- }
- }
- }
- }
- }
- }
- viewModel.SetDrawModeCommand.Execute(sender);
- }
- }
- }
|