浏览代码

组件-调整ColorContent控件,增加SelectedColor、ShowList 属性

ZhouJieSheng 2 年之前
父节点
当前提交
c1b8143a74

+ 13 - 4
PDF Office/CustomControl/CompositeControl/ColorContent.xaml

@@ -2,6 +2,7 @@
     x:Class="PDF_Office.CustomControl.CompositeControl.ColorContent"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:convert="clr-namespace:PDF_Office.DataConvert"
     xmlns:cus="clr-namespace:PDF_Office.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:local="clr-namespace:PDF_Office.CustomControl.CompositeControl"
@@ -14,6 +15,8 @@
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="../../Styles/CustomBtnStyle.xaml" />
             </ResourceDictionary.MergedDictionaries>
+
+            <convert:ColorBrushConvert x:Key="colorBrushConvert" />
             <DataTemplate x:Key="listboxData">
                 <Ellipse
                     Width="20"
@@ -69,15 +72,20 @@
                     x:Name="ElcustomColor"
                     Width="20"
                     Height="20"
-                    Fill="Transparent"
+                    Margin="4,0"
+                    Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=SelectedColor, Converter={StaticResource colorBrushConvert}}"
                     PreviewMouseLeftButtonDown="ElcustomColor_PreviewMouseLeftButtonDown" />
-                <cus:ColorDropBox x:Name="ColorDropPicker" SelectedColorChanged="ColorDropPicker_SelectedColorChanged" />
+                <cus:ColorDropBox
+                    x:Name="ColorDropPicker"
+                    Margin="4,0"
+                    SelectedColorChanged="ColorDropPicker_SelectedColorChanged" />
             </StackPanel>
         </Border>
         <cus:ColorDropBox
             x:Name="PnlColor"
             Opacity="0"
-            SelectedColorChanged="PnlColor_SelectedColorChanged" />
+            SelectedColorChanged="PnlColor_SelectedColorChanged"
+            Visibility="{Binding ElementName=ListColor, Path=Visibility}" />
 
         <ListBox
             x:Name="ListColor"
@@ -85,7 +93,8 @@
             BorderThickness="0"
             ItemContainerStyle="{StaticResource listboxItemStyle}"
             ItemTemplate="{StaticResource listboxData}"
-            SelectionChanged="ListColor_SelectionChanged">
+            SelectionChanged="ListColor_SelectionChanged"
+            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=Visibility}">
             <ListBox.ItemsPanel>
                 <ItemsPanelTemplate>
                     <WrapPanel Orientation="Horizontal" />

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

@@ -54,6 +54,12 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             Color = defaultColor;
         }
+
+
+
+
+
+
     }
 
     //类说明:
@@ -67,6 +73,31 @@ namespace PDF_Office.CustomControl.CompositeControl
         private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
         public event EventHandler<Color> SelectedColorHandler;
         private ColorItem ChangedColorItem;
+
+        /// <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 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));
+
+
         public ColorContent()
         {
             InitializeComponent();
@@ -81,7 +112,8 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             IsExistForContainer((ElcustomColor.Fill as SolidColorBrush).Color);
             SelectedColorHandler?.Invoke(this, e.Value);
-            ElcustomColor.Fill = new SolidColorBrush(e.Value);
+            //ElcustomColor.Fill = new SolidColorBrush(e.Value);
+            SelectedColor = e.Value;
         }
 
         private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)

+ 8 - 8
PDF Office/Views/Form/EditPresetColorsDialog.xaml

@@ -38,22 +38,22 @@
                     <TextBlock Text="Settings" Grid.ColumnSpan="2" VerticalAlignment="Center"/>
                     <TextBlock Text="Border Color:" Grid.Row="1" VerticalAlignment="Center"/>
                     <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
-                        <cusColor:ColorSubContent x:Name="BorderColorBox" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
-                                   ></cusColor:ColorSubContent>
+                        <cusColor:ColorContent ShowColorList="Collapsed" x:Name="BorderColorBox"  Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
+                                   ></cusColor:ColorContent>
                     </StackPanel>
 
                     <TextBlock Text="Background Color:" Grid.Row="2" VerticalAlignment="Center"/>
                     <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
-                        <cusColor:ColorSubContent x:Name="BgColorBox" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
-                                   ></cusColor:ColorSubContent>
+                        <cusColor:ColorContent x:Name="BgColorBox" ShowColorList="Collapsed" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
+                                   ></cusColor:ColorContent>
                     </StackPanel>
                     
                     <TextBlock Text="Text Color:" Grid.Row="3" VerticalAlignment="Center"/>
                     <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="1">
-                        <RadioButton Style="{StaticResource RectangleRadionButtonWithCorner}">
-                            <cusColor:ColorSubContent x:Name="TextColorBox" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
-                                   ></cusColor:ColorSubContent>
-                        </RadioButton>
+                        <!--<RadioButton Style="{StaticResource RectangleRadionButtonWithCorner}">-->
+                            <cusColor:ColorContent ShowColorList="Collapsed" x:Name="TextColorBox" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left"
+                                   ></cusColor:ColorContent>
+                        <!--</RadioButton>-->
                        
                     </StackPanel>
                 </Grid>

+ 6 - 6
PDF Office/Views/PropertyPanel/AnnotPanel/SharpsAnnotProperty.xaml.cs

@@ -47,8 +47,8 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as SquareAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.LineColor);
-                            cusFillColor.SetSelectedColor(annot.BgColor);
+                            cusColor.SelectedColor = annot.LineColor;
+                            cusFillColor.SelectedColor= annot.BgColor;
                             layerFill.SetSliOpacity(annot.Transparency);
                             SharpsBtn_Click(SharpRectBtn, null);
 
@@ -62,8 +62,8 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as CircleAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.LineColor);
-                            cusFillColor.SetSelectedColor(annot.BgColor);
+                            cusColor.SelectedColor=annot.LineColor;
+                            cusFillColor.SelectedColor=annot.BgColor;
                             layerFill.SetSliOpacity(annot.Transparency);
                             SharpsBtn_Click(SharpCircleBtn, null);
 
@@ -77,8 +77,8 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as LineAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.LineColor);
-                            cusFillColor.SetSelectedColor(annot.LineColor);
+                            cusColor.SelectedColor=annot.LineColor;
+                            cusFillColor.SelectedColor=annot.LineColor;
                             layerFill.SetSliOpacity(annot.Transparency);
 
                             if (annot.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)

+ 3 - 3
PDF Office/Views/PropertyPanel/AnnotPanel/TextAnnotProperty.xaml.cs

@@ -44,7 +44,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as TextHighlightAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.Color);
+                            cusColor.SelectedColor=annot.Color;
                             SlidOpacity.SetSliOpacity(annot.Transparency);
                         }
                         break;
@@ -55,7 +55,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as TextUnderlineAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.Color);
+                            cusColor.SelectedColor=annot.Color;
                             SlidOpacity.SetSliOpacity(annot.Transparency);
                         }
                         break;
@@ -66,7 +66,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
                         var annot = item as TextStrikeoutAnnotArgs;
                         if (annot != null)
                         {
-                            cusColor.SetSelectedColor(annot.Color);
+                            cusColor.SelectedColor=annot.Color;
                             SlidOpacity.SetSliOpacity(annot.Transparency);
                         }
                         break;