Browse Source

颜色控件选择效果

liyijie 1 year ago
parent
commit
372f1dc812

+ 3 - 3
PDF Office/CustomControl/CompositeControl/ColorContent.xaml

@@ -120,8 +120,8 @@
             CornerRadius="4">
             
                 <StackPanel Orientation="Horizontal" >
-                <Border x:Name="Grid_Color"   CornerRadius="4"  Margin="0,0" MouseDown="Grid_MouseDown" Width="28"
-                    Height="28"  Background="Transparent" >
+                <Border x:Name="Grid_Color"   CornerRadius="4"  Margin="0,0" MouseDown="Grid_MouseDown" Width="30"
+                    Height="30"  Background="Transparent" >
                     <Grid >
                     <Ellipse
                     x:Name="defaultColor"
@@ -142,7 +142,7 @@
                 </Border>
                 <cus:ColorDropBox
                     x:Name="ColorDropPicker"
-                    Margin="4,0"
+                    Margin="2,0"
                     SelectedColorChanged="ColorDropPicker_SelectedColorChanged" />
                 </StackPanel>
          

+ 49 - 36
PDF Office/CustomControl/CompositeControl/ColorContent.xaml.cs

@@ -20,7 +20,7 @@ using System.Windows.Shapes;
 
 namespace PDF_Master.CustomControl.CompositeControl
 {
-    public class ColorItem: BindableBase
+    public class ColorItem : BindableBase
     {
         public int Index = 0;
         private Brush _color;
@@ -54,7 +54,7 @@ namespace PDF_Master.CustomControl.CompositeControl
             }
         }
 
-        public ColorItem(Color color,int index = 0)
+        public ColorItem(Color color, int index = 0)
         {
             var colorBrush = new SolidColorBrush(color);
             Color = colorBrush;
@@ -91,8 +91,16 @@ namespace PDF_Master.CustomControl.CompositeControl
         }
 
         public static readonly DependencyProperty ColorTypeProperty =
-            DependencyProperty.Register("ColorType", typeof(ColorSelectorType), typeof(ColorContent), new PropertyMetadata(ColorSelectorType.Highlight));
+            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>
         /// 选中项的颜色,当前颜色
@@ -114,7 +122,7 @@ namespace PDF_Master.CustomControl.CompositeControl
         }
 
         public static readonly DependencyProperty ceshiColorProperty =
-            DependencyProperty.Register("UIColor", typeof(Brush), typeof(ColorContent), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0x6C,0x33,0xF8,0xCC)), SelectedColorPropertyChanged));
+            DependencyProperty.Register("UIColor", typeof(Brush), typeof(ColorContent), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(0x6C, 0x33, 0xF8, 0xCC)), SelectedColorPropertyChanged));
 
         public Brush DefaultColor
         {
@@ -170,15 +178,15 @@ namespace PDF_Master.CustomControl.CompositeControl
             var control = d as ColorContent;
             var co = (SolidColorBrush)e.NewValue;
             bool isFoundListItem = false;
-            if(control != null)
+            if (control != null)
             {
-                if(control.ShowColorList == Visibility.Collapsed)
+                if (control.ShowColorList == Visibility.Collapsed)
                 {
                     control.ElcustomColor.Fill = co;
                     return;
                 }
 
-                foreach(var item in control.colors)
+                foreach (var item in control.colors)
                 {
                     if (co == null) { break; }
                     var colorItem = (item.Color as SolidColorBrush).Color;
@@ -186,9 +194,10 @@ namespace PDF_Master.CustomControl.CompositeControl
                     {
                         control.ListColor.SelectedItem = item;
                         control.SelectedColor = colorItem;
-                        control.Grid_Color.Background= new SolidColorBrush(Color.FromArgb(0x00, 0xff, 0xFf, 0xff));
+                        if (control.IsColorDropPickerClick)
+                            control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0x00, 0xff, 0xFf, 0xff));
                         if (control.ElcustomColor.Fill == null) { control.ElcustomColor.Fill = co; }
-                     
+
                         isFoundListItem = true;
                         break;
                     }
@@ -198,7 +207,8 @@ namespace PDF_Master.CustomControl.CompositeControl
                 {
                     control.ElcustomColor.Fill = co;
                     control.DefaultColor = co;
-                    control.Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xe2, 0xe3, 0xe5));
+                    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;
                 }
@@ -209,16 +219,17 @@ namespace PDF_Master.CustomControl.CompositeControl
         {
             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, 0xFF, 0x10, 0x10)));
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
-            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF))); 
+            colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF)));
             ListColor.ItemsSource = colors;
         }
 
         private void ColorDropPicker_SelectedColorChanged(object sender, Color? e)
         {
-            if (ElcustomColor.Fill == null) {
-                ElcustomColor.Fill= new SolidColorBrush(Colors.Transparent);
+            if (ElcustomColor.Fill == null)
+            {
+                ElcustomColor.Fill = new SolidColorBrush(Colors.Transparent);
             }
             IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
             SelectedColorHandler?.Invoke(this, e.Value);
@@ -229,8 +240,8 @@ namespace PDF_Master.CustomControl.CompositeControl
         }
 
         private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
-        {
-       
+        {
+
         }
 
         private void listboxItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
@@ -241,8 +252,8 @@ namespace PDF_Master.CustomControl.CompositeControl
                 var selectCo = (item.Color as SolidColorBrush).Color;
                 SelectedColor = selectCo;
                 SelectedColorHandler?.Invoke(this, selectCo);
-                SelectedColorInvoke?.Invoke(selectCo, null);
-                
+                SelectedColorInvoke?.Invoke(selectCo, null);
+
             }
         }
 
@@ -299,7 +310,7 @@ namespace PDF_Master.CustomControl.CompositeControl
 
             if (newColor.A != oldColor.A || newColor.B != oldColor.B || newColor.R != oldColor.R || newColor.G != oldColor.G)
             {
-                if(ColorType != ColorSelectorType.None)
+                if (ColorType != ColorSelectorType.None)
                 {
                     ColorSelectorItem selectorItem = new ColorSelectorItem();
                     selectorItem.SelectorType = ColorType;
@@ -310,23 +321,23 @@ namespace PDF_Master.CustomControl.CompositeControl
                 }
 
                 colorIem.RestoreColor();
-                if(colorIem == ListColor.SelectedItem as ColorItem)
+                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)
-        {           
+        {
             e.Handled = true;
-        }
-        
-        //外部把颜色值传回来作为当前值
+        }
+
+        //外部把颜色值传回来作为当前值
         public void SetSelectedColor(Color newColor)
         {
             if (newColor != null)
@@ -361,20 +372,22 @@ namespace PDF_Master.CustomControl.CompositeControl
 
         private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
         {
-            Grid_Color.Background = new SolidColorBrush(Color.FromArgb(0xff, 0xe2, 0xe3, 0xe5));
+            if (IsColorDropPickerClick)
+                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();
+            Color ecolor = new Color();
             if (defaultColor.Visibility == Visibility.Visible)
             {
                 ecolor = (defaultColor.Fill as SolidColorBrush).Color;
             }
-            else {
+            else
+            {
                 ecolor = (ElcustomColor.Fill as SolidColorBrush).Color;
-            }
-            
+            }
+
             IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
             SelectedColorHandler?.Invoke(this, ecolor);
             ElcustomColor.Fill = new SolidColorBrush(ecolor);

+ 14 - 2
PDF Office/Views/Dialog/SettingsDialog.xaml

@@ -386,12 +386,12 @@
                         <Label Content="{Binding Settings_Display_Background}" Style="{StaticResource Label}" />
                         <WrapPanel Margin="0,8,0,16">
                             <Label Content="{Binding Settings_Display_Normal}" Style="{StaticResource Label2}" />
-                            <compositecontrol:ColorContent SelectedColor="{Binding View.BackGround, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ShowColorList="Collapsed" />
+                            <compositecontrol:ColorContent SelectedColor="{Binding View.BackGround, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ShowColorList="Collapsed" IsColorDropPickerClick="False"/>
                             <Label
                                 Margin="16,0,0,0"
                                 Content="{Binding Settings_Display_Full}"
                                 Style="{StaticResource Label}" />
-                            <compositecontrol:ColorContent SelectedColor="{Binding View.BackGroundInFulWindow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ShowColorList="Collapsed" />
+                            <compositecontrol:ColorContent SelectedColor="{Binding View.BackGroundInFulWindow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ShowColorList="Collapsed" IsColorDropPickerClick="False"/>
                         </WrapPanel>
                         <!--<CheckBox
                             Margin="5,0,0,8"
@@ -459,6 +459,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.HighLightColor, Mode=TwoWay}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
 
                                 <Label
@@ -469,6 +470,7 @@
                                     Grid.Column="3"
                                     Height="40"
                                     SelectedColor="{Binding Annote.RectangleFillColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="1"
@@ -480,6 +482,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.StrikethroughColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="1"
@@ -491,6 +494,7 @@
                                     Grid.Column="3"
                                     Height="40"
                                     SelectedColor="{Binding Annote.RectangleBorderColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="2"
@@ -502,6 +506,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.UnderLineColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="2"
@@ -513,6 +518,7 @@
                                     Grid.Column="3"
                                     Height="40"
                                     SelectedColor="{Binding Annote.CircleFillColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="3"
@@ -524,6 +530,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.FreeHandColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="3"
@@ -535,6 +542,7 @@
                                     Grid.Column="3"
                                     Height="40"
                                     SelectedColor="{Binding Annote.CircleBorderColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="4"
@@ -546,6 +554,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.TextAnnoteColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="4"
@@ -557,6 +566,7 @@
                                     Grid.Column="3"
                                     Height="40"
                                     SelectedColor="{Binding Annote.LineColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="5"
@@ -568,6 +578,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.NoteAnnoteColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                                 <Label
                                     Grid.Row="5"
@@ -580,6 +591,7 @@
                                     Height="40"
                                     HorizontalAlignment="Left"
                                     SelectedColor="{Binding Annote.ArrowColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                    IsColorDropPickerClick="False"
                                     ShowColorList="Collapsed" />
                             </Grid>
                         </Border>