Browse Source

文本注释-颜色更改

OYXH\oyxh 1 year ago
parent
commit
544d740c7f

+ 357 - 354
PDF Office/CustomControl/CompositeControl/ColorContent.xaml.cs

@@ -1,373 +1,376 @@
-using PDF_Master.Helper;
-using PDF_Master.Model.AnnotPanel;
-using PDFSettings;
-using Prism.Mvvm;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-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;
-
-namespace PDF_Master.CustomControl.CompositeControl
-{
-    public class ColorItem : BindableBase
-    {
-        public int Index = 0;
-        private Brush _color;
-        public Brush Color
-        {
-            get { return _color; }
-            set
-            {
-                SetProperty(ref _color, value);
-                var solid = _color as SolidColorBrush;
-                if (solid != null)
-                {
-                    if (solid.Color == Colors.Transparent || solid.Color.A == 0x00)
-                        IsTransparent = true;
-                    else
-                        IsTransparent = false;
-                }
-            }
-        }
-
-        //颜色默认值,用于恢复最初始的颜色值
-        public Brush defaultColor { get; private set; }
-
-        private bool _isTransparent;
-        public bool IsTransparent
-        {
-            get { return _isTransparent; }
-            set
-            {
-                SetProperty(ref _isTransparent, value);
-            }
-        }
-
-        public ColorItem(Color color, int index = 0)
-        {
-            var colorBrush = new SolidColorBrush(color);
-            Color = colorBrush;
-            defaultColor = colorBrush;
-            Index = index;
-        }
-
-        //恢复颜色默认值
-        public void RestoreColor()
-        {
-            Color = defaultColor;
-        }
-
-    }
-
-    //类说明:
-    //复合控件:调色板
-    //组合而成的控件:颜色圆形UI的列表容器、调色板选择的颜色圆形按钮UI,弹出调色版的按钮
-    /// <summary>
-    /// ColorContent.xaml 的交互逻辑
-    /// </summary>
-    public partial class ColorContent : UserControl
-    {
-        private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
-        public event EventHandler<Color> SelectedColorHandler;
-        public event RoutedEventHandler SelectedColorInvoke;
-        public event RoutedEventHandler DefaultColorInvoke;
-        private ColorItem ChangedColorItem;
-
-        public ColorSelectorType ColorType
-        {
-            get { return (ColorSelectorType)GetValue(ColorTypeProperty); }
-            set { SetValue(ColorTypeProperty, value); }
-        }
-
-        public static readonly DependencyProperty ColorTypeProperty =
+using PDF_Master.Helper;
+using PDF_Master.Model.AnnotPanel;
+using PDFSettings;
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+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;
+
+namespace PDF_Master.CustomControl.CompositeControl
+{
+    public class ColorItem : BindableBase
+    {
+        public int Index = 0;
+        private Brush _color;
+
+        public Brush Color
+        {
+            get { return _color; }
+            set
+            {
+                SetProperty(ref _color, value);
+                var solid = _color as SolidColorBrush;
+                if (solid != null)
+                {
+                    if (solid.Color == Colors.Transparent || solid.Color.A == 0x00)
+                        IsTransparent = true;
+                    else
+                        IsTransparent = false;
+                }
+            }
+        }
+
+        //颜色默认值,用于恢复最初始的颜色值
+        public Brush defaultColor { get; private set; }
+
+        private bool _isTransparent;
+
+        public bool IsTransparent
+        {
+            get { return _isTransparent; }
+            set
+            {
+                SetProperty(ref _isTransparent, value);
+            }
+        }
+
+        public ColorItem(Color color, int index = 0)
+        {
+            var colorBrush = new SolidColorBrush(color);
+            Color = colorBrush;
+            defaultColor = colorBrush;
+            Index = index;
+        }
+
+        //恢复颜色默认值
+        public void RestoreColor()
+        {
+            Color = defaultColor;
+        }
+    }
+
+    //类说明:
+    //复合控件:调色板
+    //组合而成的控件:颜色圆形UI的列表容器、调色板选择的颜色圆形按钮UI,弹出调色版的按钮
+    /// <summary>
+    /// ColorContent.xaml 的交互逻辑
+    /// </summary>
+    public partial class ColorContent : UserControl
+    {
+        private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
+
+        public event EventHandler<Color> SelectedColorHandler;
+
+        public event RoutedEventHandler SelectedColorInvoke;
+
+        public event RoutedEventHandler DefaultColorInvoke;
+
+        private ColorItem ChangedColorItem;
+
+        public ColorSelectorType ColorType
+        {
+            get { return (ColorSelectorType)GetValue(ColorTypeProperty); }
+            set { SetValue(ColorTypeProperty, value); }
+        }
+
+        public static readonly DependencyProperty ColorTypeProperty =
             DependencyProperty.Register("ColorType", typeof(ColorSelectorType), typeof(ColorContent), new PropertyMetadata(ColorSelectorType.Highlight));
 
-        public bool IsColorDropPickerClick
-        {
-            get { return (bool)GetValue(IsColorDropPickerClickProperty); }
-            set { SetValue(IsColorDropPickerClickProperty, value); }
-        }
-
-        public static readonly DependencyProperty IsColorDropPickerClickProperty =
-            DependencyProperty.Register("IsColorDropPickerClick", typeof(bool), typeof(ColorContent), new PropertyMetadata(true));
-
-        /// <summary>
-        /// 选中项的颜色,当前颜色
-        /// </summary>
-        public Color SelectedColor
-        {
-            get { return (Color)GetValue(SelectedColorProperty); }
-            set { SetValue(SelectedColorProperty, value); }
-        }
-
-        public static readonly DependencyProperty SelectedColorProperty =
-            DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorContent), new PropertyMetadata((Color)ColorConverter.ConvertFromString("#6C33F8CC")));
-
-        //外部传过来的颜色值,颜色列表里是否有被选中的颜色,或显示非列表里的当前颜色值
-        public Brush UIColor
-        {
-            get { return (Brush)GetValue(ceshiColorProperty); }
-            set { SetValue(ceshiColorProperty, value); }
-        }
-
-        public static readonly DependencyProperty ceshiColorProperty =
-            DependencyProperty.Register("UIColor", typeof(Brush), typeof(ColorContent), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0x6C, 0x33, 0xF8, 0xCC)), SelectedColorPropertyChanged));
-
-        public Brush DefaultColor
-        {
-            get { return (Brush)GetValue(DefaultColorProperty); }
-            set { SetValue(DefaultColorProperty, value); }
-        }
-
-        public static readonly DependencyProperty DefaultColorProperty =
+        public bool IsColorDropPickerClick
+        {
+            get { return (bool)GetValue(IsColorDropPickerClickProperty); }
+            set { SetValue(IsColorDropPickerClickProperty, value); }
+        }
+
+        public static readonly DependencyProperty IsColorDropPickerClickProperty =
+            DependencyProperty.Register("IsColorDropPickerClick", typeof(bool), typeof(ColorContent), new PropertyMetadata(true));
+
+        /// <summary>
+        /// 选中项的颜色,当前颜色
+        /// </summary>
+        public Color SelectedColor
+        {
+            get { return (Color)GetValue(SelectedColorProperty); }
+            set { SetValue(SelectedColorProperty, value); }
+        }
+
+        public static readonly DependencyProperty SelectedColorProperty =
+            DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorContent), new PropertyMetadata((Color)ColorConverter.ConvertFromString("#6C33F8CC")));
+
+        //外部传过来的颜色值,颜色列表里是否有被选中的颜色,或显示非列表里的当前颜色值
+        public Brush UIColor
+        {
+            get { return (Brush)GetValue(ceshiColorProperty); }
+            set { SetValue(ceshiColorProperty, value); }
+        }
+
+        public static readonly DependencyProperty ceshiColorProperty =
+            DependencyProperty.Register("UIColor", typeof(Brush), typeof(ColorContent), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0x6C, 0x33, 0xF8, 0xCC)), SelectedColorPropertyChanged));
+
+        public Brush DefaultColor
+        {
+            get { return (Brush)GetValue(DefaultColorProperty); }
+            set { SetValue(DefaultColorProperty, value); }
+        }
+
+        public static readonly DependencyProperty DefaultColorProperty =
             DependencyProperty.Register("DefaultColor", typeof(Brush), typeof(ColorContent), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF))));
 
-        public Visibility DefaultColorVisibility
-        {
-            get { return (Visibility)GetValue(DefaultColorVisibilityProperty); }
-            set { SetValue(DefaultColorVisibilityProperty, value); }
-        }
-
-        public static readonly DependencyProperty DefaultColorVisibilityProperty =
+        public Visibility DefaultColorVisibility
+        {
+            get { return (Visibility)GetValue(DefaultColorVisibilityProperty); }
+            set { SetValue(DefaultColorVisibilityProperty, value); }
+        }
+
+        public static readonly DependencyProperty DefaultColorVisibilityProperty =
             DependencyProperty.Register("DefaultColorVisibility", typeof(Visibility), typeof(ColorContent), new PropertyMetadata(Visibility.Collapsed));
 
-        public List<ColorItem> ItemSource
-        {
-            get { return (List<ColorItem>)GetValue(ItemSourceProperty); }
-            set { SetValue(ItemSourceProperty, value); }
-        }
-
-        // Using a DependencyProperty as the backing store for ShowColorList.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty ItemSourceProperty =
-            DependencyProperty.Register("ItemSource", typeof(List<ColorItem>), typeof(ColorContent), new PropertyMetadata(null, ItemSourcePropertyChanged));
-
-        private static void ItemSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
-        {
-            var control = d as ColorContent;
-            var co = (List<ColorItem>)e.NewValue;
-            if (control != null && co != null && control.colors != null)
-            {
-                control.colors.Clear();
-                foreach (var item in co)
-                    control.colors.Add(item);
-            }
-        }
-        public Visibility ShowColorList
-        {
-            get { return (Visibility)GetValue(ShowColorListProperty); }
-            set { SetValue(ShowColorListProperty, value); }
-        }
-
-        // Using a DependencyProperty as the backing store for ShowColorList.  This enables animation, styling, binding, etc...
-        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 = (SolidColorBrush)e.NewValue;
-            bool isFoundListItem = false;
-            if (control != null)
-            {
-                if (control.ShowColorList == Visibility.Collapsed)
-                {
-                    control.ElcustomColor.Fill = co;
-                    return;
-                }
-
-                foreach (var item in control.colors)
-                {
-                    if (co == null) { break; }
-                    var colorItem = (item.Color as SolidColorBrush).Color;
-                    if (colorItem.A == co.Color.A && colorItem.G == co.Color.G && colorItem.B == co.Color.B && colorItem.R == co.Color.R)
-                    {
-                        control.ListColor.SelectedItem = item;
-                        control.SelectedColor = colorItem;
+        public List<ColorItem> ItemSource
+        {
+            get { return (List<ColorItem>)GetValue(ItemSourceProperty); }
+            set { SetValue(ItemSourceProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ShowColorList.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ItemSourceProperty =
+            DependencyProperty.Register("ItemSource", typeof(List<ColorItem>), typeof(ColorContent), new PropertyMetadata(null, ItemSourcePropertyChanged));
+
+        private static void ItemSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var control = d as ColorContent;
+            var co = (List<ColorItem>)e.NewValue;
+            if (control != null && co != null && control.colors != null)
+            {
+                control.colors.Clear();
+                foreach (var item in co)
+                    control.colors.Add(item);
+            }
+        }
+
+        public Visibility ShowColorList
+        {
+            get { return (Visibility)GetValue(ShowColorListProperty); }
+            set { SetValue(ShowColorListProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ShowColorList.  This enables animation, styling, binding, etc...
+        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 = (SolidColorBrush)e.NewValue;
+            bool isFoundListItem = false;
+            if (control != null)
+            {
+                if (control.ShowColorList == Visibility.Collapsed)
+                {
+                    control.ElcustomColor.Fill = co;
+                    return;
+                }
+
+                foreach (var item in control.colors)
+                {
+                    if (co == null) { break; }
+                    var colorItem = (item.Color as SolidColorBrush).Color;
+                    if (colorItem.A == co.Color.A && colorItem.G == co.Color.G && colorItem.B == co.Color.B && colorItem.R == co.Color.R)
+                    {
+                        control.ListColor.SelectedItem = item;
+                        control.SelectedColor = colorItem;
                         if (control.IsColorDropPickerClick)
-                            control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0x00, 0xff, 0xFf, 0xff));
+                            control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0x00, 0xff, 0xFf, 0xff));
                         if (control.ElcustomColor.Fill == null) { control.ElcustomColor.Fill = co; }
 
-                        isFoundListItem = true;
-                        break;
-                    }
-                }
-
-                if (isFoundListItem == false)
-                {
-                    control.ElcustomColor.Fill = co;
-                    control.DefaultColor = co;
+                        isFoundListItem = true;
+                        break;
+                    }
+                }
+
+                if (isFoundListItem == false)
+                {
+                    control.ElcustomColor.Fill = co;
+                    control.DefaultColor = co;
                     if (control.IsColorDropPickerClick)
-                        control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xe2, 0xe3, 0xe5));
-                    control.DefaultColorInvoke?.Invoke(co.Color, null);
-                    control.ListColor.SelectedItem = null;
-                }
-            }
-        }
-
-        public ColorContent()
-        {
-            InitializeComponent();
-            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10)));
+                        control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xe2, 0xe3, 0xe5));
+                    control.DefaultColorInvoke?.Invoke(co.Color, null);
+                    control.ListColor.SelectedItem = null;
+                }
+            }
+        }
+
+        public ColorContent()
+        {
+            InitializeComponent();
+            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10)));
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0x10, 0x10)));
-            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
+            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF)));
-            ListColor.ItemsSource = colors;
-        }
-
-        private void ColorDropPicker_SelectedColorChanged(object sender, Color? e)
-        {
+            ListColor.ItemsSource = colors;
+        }
+
+        private void ColorDropPicker_SelectedColorChanged(object sender, Color? e)
+        {
             if (ElcustomColor.Fill == null)
             {
-                ElcustomColor.Fill = new SolidColorBrush(Colors.Transparent);
-            }
-            IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
-            SelectedColorHandler?.Invoke(this, e.Value);
-            ElcustomColor.Fill = new SolidColorBrush(e.Value);
-            SelectedColor = e.Value;
-            SelectedColorInvoke?.Invoke(e.Value, null);
-            DefaultColorInvoke?.Invoke(e.Value, null);
-        }
-
-        private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
+                ElcustomColor.Fill = new SolidColorBrush(Colors.Transparent);
+            }
+            IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
+            SelectedColorHandler?.Invoke(this, e.Value);
+            ElcustomColor.Fill = new SolidColorBrush(e.Value);
+            SelectedColor = e.Value;
+            SelectedColorInvoke?.Invoke(e.Value, null);
+            DefaultColorInvoke?.Invoke(e.Value, null);
+        }
+
+        private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
+        }
 
-        }
-
-        private void listboxItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
-        {
-            if (ListColor.SelectedItem != null)
-            {
-                var item = ListColor.SelectedItem as ColorItem;
-                var selectCo = (item.Color as SolidColorBrush).Color;
-                SelectedColor = selectCo;
-                SelectedColorHandler?.Invoke(this, selectCo);
+        private void listboxItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            if (ListColor.SelectedItem != null)
+            {
+                var item = ListColor.SelectedItem as ColorItem;
+                var selectCo = (item.Color as SolidColorBrush).Color;
+                SelectedColor = selectCo;
+                SelectedColorHandler?.Invoke(this, selectCo);
                 SelectedColorInvoke?.Invoke(selectCo, null);
+            }
+        }
 
-            }
-        }
-
-        private void ElcustomColor_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
-        {
-            var selectCo = (ElcustomColor.Fill as SolidColorBrush).Color;
-            SelectedColor = selectCo;
-            IsExistForContainer(selectCo);
-            SelectedColorHandler?.Invoke(this, selectCo);
-            SelectedColorInvoke?.Invoke(selectCo, null);
-        }
-
-        //更改颜色,选择器
-        private void PnlColor_SelectedColorChanged(object sender, Color? e)
-        {
-            ChangedColorItem.Color = new SolidColorBrush(e.Value);
-
-            if (ColorType != ColorSelectorType.None)
-            {
-                ColorSelectorItem selectorItem = new ColorSelectorItem();
-                selectorItem.SelectorType = ColorType;
-                selectorItem.color = e.Value;
-                selectorItem.Index = ChangedColorItem.Index;
-                selectorItem.IsChangedColor = true;
-                SettingHelper.SetColorSelector(selectorItem);
-            }
-
-            if (ChangedColorItem == ListColor.SelectedItem as ColorItem)
-                SelectedColorHandler?.Invoke(this, (ChangedColorItem.Color as SolidColorBrush).Color);
-        }
-
-        //列表项更改颜色
-        private void ChangeColorMenuItem_Click(object sender, RoutedEventArgs e)
-        {
-            var colorIem = (sender as FrameworkElement).DataContext as ColorItem;
-            var listBoxItem = ListColor.ItemContainerGenerator.ContainerFromItem(colorIem) as ListBoxItem;
-
-            if (listBoxItem != null)
-            {
-                ChangedColorItem = colorIem;
-                PnlColor.SelectedColor = (colorIem.Color as SolidColorBrush).Color;
-                PnlColor?.ShowLayer(listBoxItem);
-            }
-
-        }
-
-        //恢复默认颜色
-        private void BackColorMenuItem_Click(object sender, RoutedEventArgs e)
-        {
-            var colorIem = (sender as FrameworkElement).DataContext as ColorItem;
-
-            var newColor = (colorIem.Color as SolidColorBrush).Color;
-            var oldColor = (colorIem.defaultColor as SolidColorBrush).Color;
-
-            if (newColor.A != oldColor.A || newColor.B != oldColor.B || newColor.R != oldColor.R || newColor.G != oldColor.G)
-            {
-                if (ColorType != ColorSelectorType.None)
-                {
-                    ColorSelectorItem selectorItem = new ColorSelectorItem();
-                    selectorItem.SelectorType = ColorType;
-                    selectorItem.color = oldColor;
-                    selectorItem.Index = colorIem.Index;
-                    selectorItem.IsChangedColor = false;
-                    SettingHelper.SetColorSelector(selectorItem);
-                }
-
-                colorIem.RestoreColor();
-                if (colorIem == ListColor.SelectedItem as ColorItem)
-                {
-                    SelectedColorHandler?.Invoke(this, (colorIem.Color as SolidColorBrush).Color);
-                    SelectedColorInvoke?.Invoke((colorIem.Color as SolidColorBrush).Color, null);
-                }
+        private void ElcustomColor_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            var selectCo = (ElcustomColor.Fill as SolidColorBrush).Color;
+            SelectedColor = selectCo;
+            IsExistForContainer(selectCo);
+            SelectedColorHandler?.Invoke(this, selectCo);
+            SelectedColorInvoke?.Invoke(selectCo, null);
+        }
 
+        //更改颜色,选择器
+        private void PnlColor_SelectedColorChanged(object sender, Color? e)
+        {
+            ChangedColorItem.Color = new SolidColorBrush(e.Value);
+
+            if (ColorType != ColorSelectorType.None)
+            {
+                ColorSelectorItem selectorItem = new ColorSelectorItem();
+                selectorItem.SelectorType = ColorType;
+                selectorItem.color = e.Value;
+                selectorItem.Index = ChangedColorItem.Index;
+                selectorItem.IsChangedColor = true;
+                SettingHelper.SetColorSelector(selectorItem);
             }
 
+            if (ChangedColorItem == ListColor.SelectedItem as ColorItem)
+                SelectedColorHandler?.Invoke(this, (ChangedColorItem.Color as SolidColorBrush).Color);
         }
 
+        //列表项更改颜色
+        private void ChangeColorMenuItem_Click(object sender, RoutedEventArgs e)
+        {
+            var colorIem = (sender as FrameworkElement).DataContext as ColorItem;
+            var listBoxItem = ListColor.ItemContainerGenerator.ContainerFromItem(colorIem) as ListBoxItem;
 
-        private void listboxItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
+            if (listBoxItem != null)
+            {
+                ChangedColorItem = colorIem;
+                PnlColor.SelectedColor = (colorIem.Color as SolidColorBrush).Color;
+                PnlColor?.ShowLayer(listBoxItem);
+            }
+        }
+
+        //恢复默认颜色
+        private void BackColorMenuItem_Click(object sender, RoutedEventArgs e)
         {
-            e.Handled = true;
+            var colorIem = (sender as FrameworkElement).DataContext as ColorItem;
+
+            var newColor = (colorIem.Color as SolidColorBrush).Color;
+            var oldColor = (colorIem.defaultColor as SolidColorBrush).Color;
+
+            if (newColor.A != oldColor.A || newColor.B != oldColor.B || newColor.R != oldColor.R || newColor.G != oldColor.G)
+            {
+                if (ColorType != ColorSelectorType.None)
+                {
+                    ColorSelectorItem selectorItem = new ColorSelectorItem();
+                    selectorItem.SelectorType = ColorType;
+                    selectorItem.color = oldColor;
+                    selectorItem.Index = colorIem.Index;
+                    selectorItem.IsChangedColor = false;
+                    SettingHelper.SetColorSelector(selectorItem);
+                }
+
+                colorIem.RestoreColor();
+                if (colorIem == ListColor.SelectedItem as ColorItem)
+                {
+                    SelectedColorHandler?.Invoke(this, (colorIem.Color as SolidColorBrush).Color);
+                    SelectedColorInvoke?.Invoke((colorIem.Color as SolidColorBrush).Color, null);
+                }
+            }
+        }
+
+        private void listboxItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            if (sender is ListBoxItem item)
+            {
+                ListColor.SelectedItem = item.DataContext as ColorItem;
+            }
+            e.Handled = true;
         }
 
         //外部把颜色值传回来作为当前值
-        public void SetSelectedColor(Color newColor)
-        {
-            if (newColor != null)
-            {
-                if (IsExistForContainer(newColor) == false)
-                {
-                    ElcustomColor.Fill = new SolidColorBrush(newColor);
-                }
-            }
-
-        }
-
-        //颜色列表里是否存在这个颜色值
-        private bool IsExistForContainer(Color newColor)
-        {
-            bool isSelectList = false;
-            ListColor.SelectedItem = null;
-
-            foreach (var item in ListColor.Items)
-            {
-                var itemcontainer = ((item as ColorItem).Color as SolidColorBrush).Color;
-                if (itemcontainer.A == newColor.A && itemcontainer.R == newColor.R && itemcontainer.G == newColor.G && itemcontainer.B == newColor.B)
-                {
-                    isSelectList = true;
-                    ListColor.SelectedItem = item;
-                    break;
-                }
-            }
-
-            return isSelectList;
+        public void SetSelectedColor(Color newColor)
+        {
+            if (newColor != null)
+            {
+                if (IsExistForContainer(newColor) == false)
+                {
+                    ElcustomColor.Fill = new SolidColorBrush(newColor);
+                }
+            }
+        }
+
+        //颜色列表里是否存在这个颜色值
+        private bool IsExistForContainer(Color newColor)
+        {
+            bool isSelectList = false;
+            ListColor.SelectedItem = null;
+
+            foreach (var item in ListColor.Items)
+            {
+                var itemcontainer = ((item as ColorItem).Color as SolidColorBrush).Color;
+                if (itemcontainer.A == newColor.A && itemcontainer.R == newColor.R && itemcontainer.G == newColor.G && itemcontainer.B == newColor.B)
+                {
+                    isSelectList = true;
+                    ListColor.SelectedItem = item;
+                    break;
+                }
+            }
+
+            return isSelectList;
         }
 
         private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
@@ -376,24 +379,24 @@ namespace PDF_Master.CustomControl.CompositeControl
                 Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xe2, 0xe3, 0xe5));
             if (ElcustomColor.Fill == null)
             {
-                ElcustomColor.Fill = new SolidColorBrush(Colors.Transparent);
-            }
-            Color ecolor = new Color();
+                ElcustomColor.Fill = new SolidColorBrush(Colors.Transparent);
+            }
+            Color ecolor = new Color();
             if (defaultColor.Visibility == Visibility.Visible)
             {
-                ecolor = (defaultColor.Fill as SolidColorBrush).Color;
+                ecolor = (defaultColor.Fill as SolidColorBrush).Color;
             }
             else
             {
-                ecolor = (ElcustomColor.Fill as SolidColorBrush).Color;
+                ecolor = (ElcustomColor.Fill as SolidColorBrush).Color;
             }
 
-            IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
-            SelectedColorHandler?.Invoke(this, ecolor);
-            ElcustomColor.Fill = new SolidColorBrush(ecolor);
-            SelectedColor = ecolor;
-            SelectedColorInvoke?.Invoke(ecolor, null);
+            IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
+            SelectedColorHandler?.Invoke(this, ecolor);
+            ElcustomColor.Fill = new SolidColorBrush(ecolor);
+            SelectedColor = ecolor;
+            SelectedColorInvoke?.Invoke(ecolor, null);
             DefaultColorInvoke?.Invoke(ecolor, null);
         }
-    }
-}
+    }
+}

+ 1 - 1
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml

@@ -453,7 +453,7 @@
                     Margin="0,8,0,0"
                     ColorType="Fill"
                     ItemSource="{Binding BasicVm.FillColorItems}"
-                    UIColor="{Binding BasicVm.CurrentFillColor, Mode=OneWay}">
+                    UIColor="{Binding BasicVm.CurrentFillColor, Mode=TwoWay}">
                     <i:Interaction.Triggers>
                         <i:EventTrigger EventName="SelectedColorInvoke">
                             <i:InvokeCommandAction Command="{Binding SelectedFillColorCommand}" CommandParameter="{Binding ElementName=cusColor, Path=SelectedColor}" />

+ 12 - 1
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml.cs

@@ -23,9 +23,20 @@ namespace PDF_Master.Views.PropertyPanel.AnnotPanel
     /// </summary>
     public partial class FreetextAnnotProperty : UserControl
     {
+        private FreetextAnnotPropertyViewModel ViewModel => DataContext as FreetextAnnotPropertyViewModel;
+
         public FreetextAnnotProperty()
         {
             InitializeComponent();
+            cusColor.SelectedColorHandler += cusColor_SelectedColor;
+        }
+
+        private void cusColor_SelectedColor(object sender, Color e)
+        {
+            if (ViewModel != null)
+            {
+                ViewModel.SelectedFillColorCommand?.Execute(e);
+            }
         }
     }
-}
+}