Przeglądaj źródła

其他-颜色选择器BUG修复

zhuyi 1 rok temu
rodzic
commit
c6ee971548

+ 2 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml

@@ -353,7 +353,7 @@
                             HorizontalAlignment="Right"
                             VerticalAlignment="Center"
                             Orientation="Horizontal">
-                        <common:ColorPickerControl x:Name="ColorPickerControl" SelectedIndexProperty="1"  ColorChanged="ColorPickerControl_ColorChanged"></common:ColorPickerControl>
+                        <common:ColorPickerControl x:Name="ColorPickerControl" Loaded="ColorPickerControl_Loaded" ColorChanged="ColorPickerControl_ColorChanged"></common:ColorPickerControl>
                     </StackPanel>
                 </Grid>
             </TabItem>
@@ -393,7 +393,7 @@
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
                         Orientation="Horizontal">
-                        <common:ColorPickerControl x:Name="TextColorPickerControl" SelectedIndexProperty="1" ColorChanged="TextColorPickerControl_ColorChanged"></common:ColorPickerControl>
+                        <common:ColorPickerControl x:Name="TextColorPickerControl" Loaded="TextColorPickerControl_Loaded" ColorChanged="TextColorPickerControl_ColorChanged"></common:ColorPickerControl>
                     </StackPanel>
                 </Grid>
             </TabItem>

+ 12 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml.cs

@@ -80,8 +80,8 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 
         private void Clear_Click(object sender, RoutedEventArgs e)
         {
-            ColorPickerControl.SelectedIndexProperty = 1;
-            TextColorPickerControl.SelectedIndexProperty = 1;
+            ColorPickerControl.SetIsChecked(1);
+            TextColorPickerControl.SetIsChecked(1);
 
             DrawinkCanvas.Strokes.Clear();
             InPutTextBox.Text = "";
@@ -418,5 +418,15 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                 UpDataToStrokesObject();
             }
         }
+
+        private void ColorPickerControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            ColorPickerControl.SetIsChecked(1);
+        }
+
+        private void TextColorPickerControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            TextColorPickerControl.SetIsChecked(1);
+        }
     }
 }

+ 13 - 52
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/ColorPickerControl.xaml

@@ -7,8 +7,6 @@
              xmlns:local="clr-namespace:compdfkit_tools.Common" xmlns:convert="clr-namespace:compdfkit_tools.Common.Convert"
              d:DesignHeight="40" d:DesignWidth="220">
     <UserControl.Resources>
-
-        <convert:IntAndTagToBoolMultiBinding x:Key="IntAndTagToBoolMultiBinding"/>
         <convert:UnVisivleConvert x:Key="UnVisivleConvert"/>
         <Style x:Key="TransparentRadioButton" TargetType="{x:Type RadioButton}">
             <Setter Property="HorizontalAlignment" Value="Center" />
@@ -114,7 +112,7 @@
                                         <ColumnDefinition Width="*"/>
                                     </Grid.ColumnDefinitions>
                                     <Ellipse Panel.ZIndex="2" Width="24" Height="24" Fill="{TemplateBinding Background}" />
-                                  
+
                                     <Ellipse Grid.Column="1"  Margin="2" Width="24" Height="24">
                                         <Ellipse.Fill>
                                             <DrawingBrush>
@@ -152,55 +150,18 @@
             <ColumnDefinition></ColumnDefinition>
             <ColumnDefinition Width="2*"></ColumnDefinition>
         </Grid.ColumnDefinitions>
-        <StackPanel></StackPanel>
-        <RadioButton  Background="Transparent" x:Name="TransparentBtn" Style="{StaticResource TransparentRadioButton}" Tag="0" Click="ColorRadioButton_Click" Visibility="{Binding TransparentBtnProperty, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}">
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="0" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
-        <RadioButton  Background="#000000" Style="{StaticResource CommonColorRadioButton}" Tag="0" Click="ColorRadioButton_Click" Visibility="{Binding ElementName=TransparentBtn, Path=Visibility, Converter={StaticResource UnVisivleConvert}}">
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="0" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
-        <RadioButton  Background="#FF0000" Grid.Column="1" Style="{StaticResource CommonColorRadioButton}" Tag="1" Click="ColorRadioButton_Click" >
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="1" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
-        <RadioButton  Background="#FFEC66" Grid.Column="2" Style="{StaticResource CommonColorRadioButton}" Tag="2" Click="ColorRadioButton_Click">
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="2" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty"  RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
-        <RadioButton  Background="#2D77FA" Grid.Column="3" Style="{StaticResource CommonColorRadioButton}" Tag="3"  Click="ColorRadioButton_Click">
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="3" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
 
-        <RadioButton x:Name="CustomColorRadioButton" Background="{Binding Brush, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}" Tag="4" Grid.Column="4" Style="{StaticResource CustomColorRadioButton}" Click="CustomColorRadioButton_Click">
-            <RadioButton.IsChecked>
-                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="4" Mode="TwoWay">
-                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
-                    <Binding Path="SelectedIndexProperty"  RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:ColorPickerControl}}"/>
-                </MultiBinding>
-            </RadioButton.IsChecked>
-        </RadioButton>
+        <RadioButton  x:Name="TransparentBtn"  Background="Transparent" Style="{StaticResource TransparentRadioButton}" Tag="-1" Click="ColorRadioButton_Click" Visibility="{Binding TransparentBtnProperty, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}"/>
+
+        <RadioButton  x:Name="FirstBtn"  Background="#000000" Style="{StaticResource CommonColorRadioButton}" Tag="0" Click="ColorRadioButton_Click" Visibility="{Binding ElementName=TransparentBtn, Path=Visibility, Converter={StaticResource UnVisivleConvert}}"/>
+
+        <RadioButton  x:Name="SecondBtn"  Background="#FF0000" Grid.Column="1" Style="{StaticResource CommonColorRadioButton}" Tag="1" Click="ColorRadioButton_Click" />
+
+        <RadioButton   x:Name="ThirdBtn" Background="#FFEC66" Grid.Column="2" Style="{StaticResource CommonColorRadioButton}" Tag="2" Click="ColorRadioButton_Click"/>
+
+        <RadioButton  x:Name="FourthBtn" Background="#2D77FA" Grid.Column="3" Style="{StaticResource CommonColorRadioButton}" Tag="3"  Click="ColorRadioButton_Click"/>
+
+        <RadioButton x:Name="CustomColorRadioButton" Background="{Binding Brush, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}" Tag="4" Grid.Column="4" Style="{StaticResource CustomColorRadioButton}" Click="CustomColorRadioButton_Click"/>
+
     </Grid>
 </UserControl>

+ 44 - 13
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/ColorPickerControl.xaml.cs

@@ -40,27 +40,58 @@ namespace compdfkit_tools.Common
             DependencyProperty.Register("TransparentBtnProperty", typeof(Visibility), typeof(ColorPickerControl), new PropertyMetadata(Visibility.Visible));
 
 
-
-        public int SelectedIndexProperty
+        public void SetIsChecked(int index)
         {
-            get { return (int)GetValue(SelectedIndexPropertyProperty); }
-            set
+            switch (index)
             {
-                SetValue(SelectedIndexPropertyProperty, value);
+                case -1:
+                    TransparentBtn.IsChecked = true;
+                    break;
+                case 0:
+                    FirstBtn.IsChecked = true;
+                    break;
+                case 1:
+                    SecondBtn.IsChecked = true;
+                    break;
+                case 2:
+                    ThirdBtn.IsChecked = true;
+                    break;
+                case 3:
+                    FourthBtn.IsChecked = true;
+                    break;
+                case 4:
+                    CustomColorRadioButton.IsChecked = true;
+                    break;
+                default:
+                    break;
             }
-        }
 
-        // Using a DependencyProperty as the backing store for SelectedIndex.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty SelectedIndexPropertyProperty =
-            DependencyProperty.Register("SelectedIndexProperty", typeof(int), typeof(ColorPickerControl), new PropertyMetadata(0, OnMyPropChanged));
+        }
 
-        private static void OnMyPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        public void SetButtonColor(List<SolidColorBrush> list)
         {
-            var x = 1;
+            for (int i = 0; i < list.Count; i++)
+            {
+                switch (i)
+                {
+                    case 0:
+                        FirstBtn.Background = list[i];
+                        break;
+                    case 1:
+                        SecondBtn.Background = list[i];
+                        break;
+                    case 2:
+                        ThirdBtn.Background = list[i];
+                        break;
+                    case 3:
+                        FourthBtn.Background = list[i];
+                        break;
+                    default:
+                        break;
+                }
+            }
         }
 
-
-
         /// <summary>
         /// 设置允许为空
         /// </summary>