Browse Source

ComPDFKit.Demo(win) - 修复文字编辑给属性面板字体透明度赋值时导致透明度被重新设置的问题

TangJinZhou 2 months ago
parent
commit
4cb7e7c188

+ 9 - 26
Demo/Examples/Compdfkit.Controls/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -92,8 +92,11 @@ namespace ComPDFKit.Controls.Edit
                 TextStyleUI.SelectFontName(defaultEvent.FontName);
                 TextStyleUI.SelectFontName(defaultEvent.FontName);
                 TextStyleUI.SetFontStyle(defaultEvent.IsBold, defaultEvent.IsItalic);
                 TextStyleUI.SetFontStyle(defaultEvent.IsBold, defaultEvent.IsItalic);
                 TextStyleUI.SetFontSize(defaultEvent.FontSize);
                 TextStyleUI.SetFontSize(defaultEvent.FontSize);
-                OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(defaultEvent.Transparency * 100 / 255D)));
+
+                FontOpacitySlider.Tag = "false";
                 FontOpacitySlider.Value = ((int)(Math.Ceiling(defaultEvent.Transparency * 100 / 255D))) / 100D;
                 FontOpacitySlider.Value = ((int)(Math.Ceiling(defaultEvent.Transparency * 100 / 255D))) / 100D;
+                FontOpacitySlider.Tag = "true";
+
                 TextAlignUI.SetFontAlign(defaultEvent.TextAlign);
                 TextAlignUI.SetFontAlign(defaultEvent.TextAlign);
                 if (defaultEvent.FontColor != null && defaultEvent.FontColor.Length == 3)
                 if (defaultEvent.FontColor != null && defaultEvent.FontColor.Length == 3)
                 {
                 {
@@ -143,12 +146,7 @@ namespace ComPDFKit.Controls.Edit
 
 
         private void SliderOpacity_DragCompleted(object sender, DragCompletedEventArgs e)
         private void SliderOpacity_DragCompleted(object sender, DragCompletedEventArgs e)
         {
         {
-            Slider slider = sender as Slider;
-            if (slider != null)
-            {
-                slider.Tag = "true";
-            }
-
+            FontOpacitySlider.Tag = "true";
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
             if (textAreas.Count == 0 || pdfPage == null || editPage == null)
             if (textAreas.Count == 0 || pdfPage == null || editPage == null)
                 return;
                 return;
@@ -211,13 +209,12 @@ namespace ComPDFKit.Controls.Edit
 
 
         private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
         private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
         {
         {
-            Slider slider = sender as Slider;
             if (OpacityTextBox != null && FontOpacitySlider != null)
             if (OpacityTextBox != null && FontOpacitySlider != null)
             {
             {
-                OpacityTextBox.Text = string.Format("{0}%", (int)(FontOpacitySlider.Value * 100));
+                OpacityTextBox.Text = string.Format("{0}%", (int)(FontOpacitySlider.Value * 100D));
             }
             }
 
 
-            if (slider != null && slider.Tag != null && slider.Tag.ToString() == "false")
+            if (FontOpacitySlider.Tag == null || FontOpacitySlider.Tag.ToString() == "false")
             {
             {
                 return;
                 return;
             }
             }
@@ -284,11 +281,7 @@ namespace ComPDFKit.Controls.Edit
 
 
         private void Slider_DragStarted(object sender, DragStartedEventArgs e)
         private void Slider_DragStarted(object sender, DragStartedEventArgs e)
         {
         {
-            Slider slider = sender as Slider;
-            if (slider != null)
-            {
-                slider.Tag = "false";
-            }
+            FontOpacitySlider.Tag = "false";
         }
         }
         #endregion
         #endregion
 
 
@@ -317,7 +310,6 @@ namespace ComPDFKit.Controls.Edit
         #endregion
         #endregion
 
 
         #region Property changed
         #region Property changed
-
         private void TextStyleUI_TextSizeChanged(object sender, double e)
         private void TextStyleUI_TextSizeChanged(object sender, double e)
         {
         {
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
             GetTextArea(out List<CPDFEditTextArea> textAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
@@ -750,7 +742,6 @@ namespace ComPDFKit.Controls.Edit
             {
             {
                 if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double newOpacity))
                 if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double newOpacity))
                 {
                 {
-                    OpacityTextBox.Text = selectItem.Content.ToString();
                     FontOpacitySlider.Value = newOpacity / 100.0;
                     FontOpacitySlider.Value = newOpacity / 100.0;
                 }
                 }
             }
             }
@@ -768,6 +759,7 @@ namespace ComPDFKit.Controls.Edit
             {
             {
                 return;
                 return;
             }
             }
+
             if (EditEvents != null && EditEvents.Count>0 )
             if (EditEvents != null && EditEvents.Count>0 )
             {
             {
                 try
                 try
@@ -790,15 +782,6 @@ namespace ComPDFKit.Controls.Edit
 
 
                 }
                 }
             }
             }
-            else
-            {
-                CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
-                CPDFDocument pdfDoc = pdfViewer.GetDocument();
-                pdfPage = pdfDoc.PageAtIndex(0);
-                editPage = pdfPage.GetEditPage();
-                editPage.BeginEdit(CPDFEditType.EditText);
-                editPage.EndEdit();
-            }
         }
         }
         #endregion
         #endregion