瀏覽代碼

优化 - 调色板选中颜色列表、预设样式类重名、手绘颜色变化

chenrongqian@kdanmobile.com 2 年之前
父節點
當前提交
bec1a16d8c

+ 22 - 1
PDF Office/CustomControl/CompositeControl/ColorContent.xaml.cs

@@ -85,7 +85,7 @@ namespace PDF_Office.CustomControl.CompositeControl
         }
 
         public static readonly DependencyProperty SelectedColorProperty =
-            DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorContent), new PropertyMetadata((Color)ColorConverter.ConvertFromString("#6C33F8CC")));
+            DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorContent), new PropertyMetadata((Color)ColorConverter.ConvertFromString("#6C33F8CC"), SelectedColorPropertyChanged));
 
 
         public Visibility ShowColorList
@@ -98,6 +98,27 @@ namespace PDF_Office.CustomControl.CompositeControl
         public static readonly DependencyProperty ShowColorListProperty =
             DependencyProperty.Register("ShowColorList", typeof(Visibility), typeof(ColorContent), new PropertyMetadata(Visibility.Visible));
 
+        private static void SelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var control = d as ColorContent;
+            var co = (Color)e.NewValue;
+            if(control != null)
+            {
+                foreach(var item in control.colors)
+                {
+                    var colorItem = (item.Color as SolidColorBrush).Color;
+                    if(colorItem.A == co.A && colorItem.G == co.G && colorItem.B == co.B && colorItem.R == co.R)
+                    {
+                        control.ListColor.SelectedItem = item;
+                        break;
+                    }
+                    else
+                    {
+                        control.ListColor.SelectedItem = null;
+                    }
+                }
+            }
+        }
 
         public ColorContent()
         {

+ 9 - 4
PDF Office/Helper/PopControlHelper.cs

@@ -223,10 +223,11 @@ namespace PDF_Office.Helper
     {
         public ContextMenu PopMenu { get; private set; }
         public List<MenuItem> MenuItems { get; private set; }
-
-        public CustomPopMenu(ContextMenu popMenu)
+        private object CommandTarget { get; set; }
+        public CustomPopMenu(ContextMenu popMenu,object commandTarget)
         {
             PopMenu = popMenu;
+            CommandTarget = commandTarget;
             GetMenuItems();
         }
 
@@ -310,13 +311,17 @@ namespace PDF_Office.Helper
             }
         }
 
-        public void SetMenuBinding(int index, object commandTarget, ICommand command)
+        public void SetMenuBinding(int index, ICommand command,object commandTarget = null)
         {
             var menuItem = ContainterOfIndex(index);
 
             if (menuItem != null)
             {
-                menuItem.CommandTarget = (UIElement)commandTarget;
+                if (commandTarget != null)
+                    menuItem.CommandTarget = (UIElement)commandTarget;
+                else
+                    menuItem.CommandTarget = (UIElement)CommandTarget;
+
                 menuItem.Command = command;
             }
 

+ 10 - 10
PDF Office/Model/PropertyPanel/AnnotPanel/FontStyleItem.cs

@@ -11,7 +11,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
 {
     #region 自定义文字样式选项
 
-    public class FontStyleItem
+    public class PresetFontItem
     {
         public string mTag { get; set; }
 
@@ -28,10 +28,10 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
 
     public class TextFont
     {
-        public static List<FontStyleItem> GetPresetFontStyle()
+        public static List<PresetFontItem> GetPresetFontStyle()
         {
-            List<FontStyleItem> fontStyleList = new List<FontStyleItem>();
-            FontStyleItem custom = new FontStyleItem();
+            List<PresetFontItem> fontStyleList = new List<PresetFontItem>();
+            PresetFontItem custom = new PresetFontItem();
             custom.mTag = "custom";
             custom.mTagContent = "自定义";
 
@@ -40,7 +40,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             custom.mFontStyle = FontStyles.Normal;
             custom.mFontWeight = FontWeights.Normal;
 
-            FontStyleItem h1 = new FontStyleItem();
+            PresetFontItem h1 = new PresetFontItem();
             h1.mTag = "H1";
             h1.mTagContent = "H1大标题";
 
@@ -49,7 +49,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             h1.mFontStyle = FontStyles.Normal;
             h1.mFontWeight = FontWeights.Normal;
 
-            FontStyleItem h2 = new FontStyleItem();
+            PresetFontItem h2 = new PresetFontItem();
             h2.mTag = "H2";
             h2.mTagContent = "h2(标准)";
 
@@ -59,7 +59,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             h2.mFontWeight = FontWeights.Bold;
 
 
-            FontStyleItem h3 = new FontStyleItem();
+            PresetFontItem h3 = new PresetFontItem();
             h3.mTag = "H3";
             h3.mTagContent = "H3小标题";
 
@@ -68,7 +68,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             h3.mFontStyle = FontStyles.Normal;
             h3.mFontWeight = FontWeights.Bold;
 
-            FontStyleItem b1 = new FontStyleItem();
+            PresetFontItem b1 = new PresetFontItem();
             b1.mTag = "B1";
             b1.mTagContent = "B1标题";
 
@@ -78,7 +78,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             b1.mFontWeight = FontWeights.Normal;
 
 
-            FontStyleItem b2 = new FontStyleItem();
+            PresetFontItem b2 = new PresetFontItem();
             b2.mTag = "B2";
             b2.mTagContent = "B2标题";
 
@@ -87,7 +87,7 @@ namespace PDF_Office.Model.PropertyPanel.AnnotPanel
             b2.mFontStyle = FontStyles.Normal;
             b2.mFontWeight = FontWeights.Normal;
 
-            FontStyleItem b3 = new FontStyleItem();
+            PresetFontItem b3 = new PresetFontItem();
             b3.mTag = "B3";
             b3.mTagContent = "B3标题";
 

+ 2 - 1
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreehandAnnotPropertyViewModel.cs

@@ -107,7 +107,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand<object> LineModeCheckedCommand { get; set; }
         public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
 
-        
+        public event EventHandler<object> LoadPropertyHandler;
 
 
         public FreehandAnnotPropertyViewModel()
@@ -261,6 +261,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 AnnotEvent = PropertyPanel.AnnotEvent;
                 Annot = PropertyPanel.annot;
                 GetAnnotProperty();
+                LoadPropertyHandler?.Invoke(null, (Annot as FreehandAnnotArgs).InkColor);
             }
         }
 

+ 4 - 4
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -95,8 +95,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-        private List<FontStyleItem> fontStyleList = new List<FontStyleItem>();
-        public List<FontStyleItem> FontStyleList
+        private List<PresetFontItem> fontStyleList = new List<PresetFontItem>();
+        public List<PresetFontItem> FontStyleList
         {
             get { return fontStyleList; }
             set
@@ -302,9 +302,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         private void SelectedFontStyle(object obj)
         {
-            if (obj != null && (FontStyleItem)obj != null)
+            if (obj != null && (PresetFontItem)obj != null)
             {
-                var item = (FontStyleItem)obj;
+                var item = (PresetFontItem)obj;
 
                 AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, item.mFontSize);
 

+ 1 - 1
PDF Office/ViewModels/PropertyPanel/FontSetModeVM.cs

@@ -32,7 +32,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
         public List<ComboDataItem> FontStyleItems { get; protected set; }
         public List<ComboDataItem> PresetTextItems { get; protected set; }
 
-        public List<FontStyleItem> FontStyleList = new List<FontStyleItem>();
+        public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
 
         #endregion
 

+ 31 - 1
PDF Office/Views/PropertyPanel/AnnotPanel/FreehandAnnotProperty.xaml.cs

@@ -21,13 +21,43 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
     /// </summary>
     public partial class FreehandAnnotProperty : UserControl
     {
+        private FreehandAnnotPropertyViewModel ViewModel => DataContext as FreehandAnnotPropertyViewModel;
         public FreehandAnnotProperty()
         {
             InitializeComponent();
+            this.Loaded += usercontrol_Loaded;
+            this.Unloaded += usercontrol_Unloaded;
+        }
+
+        private void usercontrol_Unloaded(object sender, RoutedEventArgs e)
+        {
+            if (ViewModel != null)
+            {
+                ViewModel.LoadPropertyHandler -= ViewModel_LoadPropertyHandler;
+            }
+            cusColor.SelectedColorHandler -= cusColor_SelectedColor;
+        }
+
+        private void usercontrol_Loaded(object sender, RoutedEventArgs e)
+        {
+            if (ViewModel != null)
+            {
+                ViewModel.LoadPropertyHandler -= ViewModel_LoadPropertyHandler;
+                ViewModel.LoadPropertyHandler += ViewModel_LoadPropertyHandler;
+            }
             cusColor.SelectedColorHandler += cusColor_SelectedColor;
-           // layerThick.SelectedValueChanged += layerThick_SelectedValue;
         }
 
+        private void ViewModel_LoadPropertyHandler(object sender, object e)
+        {
+            if(e != null && e is Color == true)
+            {
+                var color = (Color)e;
+                cusColor.SelectedColor = color;
+            }
+            
+
+        }
         private void layerThick_SelectedValue(object sender, double e)
         {
             var data = this.DataContext as FreehandAnnotPropertyViewModel;