Browse Source

ComPDFKit(windows) - 整合

liuaoran 1 year ago
parent
commit
6f42c7088f

+ 4 - 0
compdfkit_demo_windows/compdfkit/annotation-ctrl-demo/MainWindow.xaml.cs

@@ -838,6 +838,10 @@ namespace viewer_ctrl_demo
             PropertyContainer.Width = 260;
             PropertyContainer.Child = properytPanel;
             PropertyContainer.Visibility = visible;
+            if (visible == Visibility.Collapsed||visible == Visibility.Hidden)
+            {
+                AnnotationBarBtn.IsChecked = false;
+            }
         }
 
         private void EditLink_Click(object sender, RoutedEventArgs e)

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

@@ -15,7 +15,7 @@
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ButtonStyle.xaml"></ResourceDictionary>
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
-            <convert:UnVisivleConvert x:Key="UnVisivleConvert"/>
+            <convert:ReverseVisibilityConvert x:Key="ReverseVisibilityConvert"/>
             <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
             <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/>
             <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}">
@@ -421,7 +421,7 @@
                             <TextBlock Text="or"  HorizontalAlignment="Center"/>
                             <Button  x:Name="AddImageBtn" Style="{DynamicResource LinkButton}" HorizontalAlignment="Center" Content="Select a File" Click="OpenImage_Click"/>
                         </StackPanel>
-                        <Image x:Name="ImageImage" SourceUpdated="ImageImage_SourceUpdated" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center"  Grid.ColumnSpan="4" Visibility="{Binding ElementName=AddImageBtn,Path=Visibility, Converter={StaticResource UnVisivleConvert}}"/>
+                        <Image x:Name="ImageImage" SourceUpdated="ImageImage_SourceUpdated" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center"  Grid.ColumnSpan="4" Visibility="{Binding ElementName=AddImageBtn,Path=Visibility, Converter={StaticResource ReverseVisibilityConvert}}"/>
                     </Grid>
                 </Grid>
             </TabItem>

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

@@ -16,7 +16,7 @@
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ButtonStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
-            <convert:UnVisivleConvert x:Key="UnVisivleConvert"/>
+            <convert:ReverseVisibilityConvert x:Key="ReverseVisibilityConvert"/>
             <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
             <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/>
             <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}">
@@ -391,7 +391,7 @@
                             <TextBlock Text="or"  HorizontalAlignment="Center"/>
                             <Button  x:Name="AddImageBtn" Style="{DynamicResource LinkButton}" HorizontalAlignment="Center" Content="Select a File" Click="OpenImage_Click"/>
                         </StackPanel>
-                        <Image x:Name="ImageImage" SourceUpdated="ImageImage_SourceUpdated" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center"  Grid.ColumnSpan="4" Visibility="{Binding ElementName=AddImageBtn,Path=Visibility, Converter={StaticResource UnVisivleConvert}}"/>
+                        <Image x:Name="ImageImage" SourceUpdated="ImageImage_SourceUpdated" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center"  Grid.ColumnSpan="4" Visibility="{Binding ElementName=AddImageBtn,Path=Visibility, Converter={StaticResource ReverseVisibilityConvert}}"/>
                     </Grid>
                 </Grid>
             </TabItem>

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/Convert/UnVisivleConvert.cs

@@ -9,7 +9,7 @@ using System.Windows.Data;
 
 namespace compdfkit_tools.Common.Convert
 {
-    public class UnVisivleConvert : IValueConverter
+    public class ReverseVisibilityConvert : IValueConverter
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {

+ 2 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/ColorPickerControl.xaml

@@ -7,7 +7,7 @@
              xmlns:local="clr-namespace:compdfkit_tools.Common" xmlns:convert="clr-namespace:compdfkit_tools.Common.Convert"
              d:DesignHeight="40" d:DesignWidth="220">
     <UserControl.Resources>
-        <convert:UnVisivleConvert x:Key="UnVisivleConvert"/>
+        <convert:ReverseVisibilityConvert x:Key="ReverseVisibilityConvert"/>
         <Style x:Key="TransparentRadioButton" TargetType="{x:Type RadioButton}">
             <Setter Property="HorizontalAlignment" Value="Center" />
             <Setter Property="VerticalAlignment" Value="Center" />
@@ -153,7 +153,7 @@
 
         <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="FirstBtn"  Background="#000000" Style="{StaticResource CommonColorRadioButton}" Tag="0" Click="ColorRadioButton_Click" Visibility="{Binding ElementName=TransparentBtn, Path=Visibility, Converter={StaticResource ReverseVisibilityConvert}}"/>
 
         <RadioButton  x:Name="SecondBtn"  Background="#FF0000" Grid.Column="1" Style="{StaticResource CommonColorRadioButton}" Tag="1" Click="ColorRadioButton_Click" />
 

+ 6 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Edit/PDFImageEdit/PDFImageEditControl/PDFImageEditControl.xaml.cs

@@ -32,8 +32,14 @@ namespace compdfkit_tools.Edit
         {
             InitializeComponent();
             Loaded += PDFImageEditControl_Loaded;
+            Unloaded += PDFImageEditControl_Unloaded;
         }
 
+        private void PDFImageEditControl_Unloaded(object sender, RoutedEventArgs e)
+        {
+            RotateUI.RotationChanged -= RotateUI_RotationChanged;
+            FlipUI.FlipChanged -= FlipUI_FlipChanged;
+        }
 
         public void InitWithPDFViewer(CPDFViewer newPDFView)
         {

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/compdfkit-tools.csproj

@@ -95,7 +95,7 @@
       <DependentUpon>CPDFDeleteDialog.xaml</DependentUpon>
     </Compile>
     <Compile Include="Common\Convert\IntAndTagToBoolMultiBinding.cs" />
-    <Compile Include="Common\Convert\UnVisivleConvert.cs" />
+    <Compile Include="Common\Convert\ReverseVisibilityConvert.cs" />
     <Compile Include="Common\PasswordControl\PasswordDialog.xaml.cs">
       <DependentUpon>PasswordDialog.xaml</DependentUpon>
     </Compile>

+ 86 - 1
compdfkit_demo_windows/compdfkit/compdfkit/MainWindow.xaml

@@ -273,7 +273,92 @@
                         <RowDefinition Height="*"/>
                     </Grid.RowDefinitions>
 
-                    <Border x:Name="ToolBarContainer" Height="44" Visibility="Collapsed"></Border>
+                    <Border x:Name="ToolBarContainer" Height="44" Visibility="Collapsed"  BorderThickness="1" BorderBrush="#1A000000" Background="#F2F3F5">
+
+                        <Grid>
+                            <cpdftools:CPDFAnnotationBarControl x:Name="AnnotationBarControl" Height="44" Loaded="AnnotationBarControl_Loaded" Unloaded="AnnotationBarControl_Unloaded"/>
+                            
+                            <Border Name="PDFEditTool" Background="#F2F3F5" Visibility="Collapsed">
+                                <StackPanel  Orientation="Horizontal" HorizontalAlignment="Center"> 
+                                    <!--文字编辑按钮-->
+                                    <ToggleButton Style="{StaticResource ToggleButtonStyle}" Name="PDFTextEditButton" BorderThickness="0" Padding="10,5,10,5" Click="PDFTextEditButton_Click" Width="99" Height="40">
+                                        <StackPanel Orientation="Horizontal">
+                                            <Path Fill="#273C62" VerticalAlignment="Center">
+                                                <Path.Data>
+                                                    M1.25 0H0.5V0.75V13.25V14H1.25H17.75H18.5V13.25V7H17V12.5H2V1.5H12.5V0H1.25ZM11.5 5V2.5H3.5V5H5V4H6.75V10H6V11.5H9V10H8.25V4H10V5H11.5ZM15.75 
+                                3.75H13.5V2.25H15.75V0H17.25V2.25H19.5V3.75H17.25V6H15.75V3.75Z
+                                                </Path.Data>
+                                            </Path>
+                                            <TextBlock  FontSize="12" VerticalAlignment="Center" Margin="8,0,0,0">Add Text</TextBlock>
+                                        </StackPanel>
+                                    </ToggleButton>
+
+                                    <!--图片编辑按钮-->
+                                    <ToggleButton Style="{StaticResource ToggleButtonStyle}" Name="PDFImageEditButton" BorderThickness="0" Padding="10,5,10,5" Margin="10,0,0,0" Click="PDFImageEditButton_Click">
+                                        <StackPanel Orientation="Horizontal">
+                                            <Path Fill="#273C62" VerticalAlignment="Center">
+                                                <Path.Data>
+                                                    M1.5 0H0.75V0.75V13.25V14H1.5H18H18.75V13.25V7H17.25V12.5H17.2147L11.8718 7.81776L9.56428 10.25L5.29496 6.75L2.25 9.95948V1.5H12.75V0H1.5ZM13.5 5.25C13.5 
+                                            6.07843 12.8284 6.75 12 6.75C11.1716 6.75 10.5 6.07843 10.5 5.25C10.5 4.42157 11.1716 3.75 12 3.75C12.8284 3.75 13.5 4.42157 13.5 5.25ZM15.75 
+                                            3.75H13.5V2.25H15.75V0H17.25V2.25H19.5V3.75H17.25V6H15.75V3.75Z
+                                                </Path.Data>
+                                            </Path>
+                                            <TextBlock  FontSize="12" VerticalAlignment="Center" Margin="8,0,0,0">Add Picture</TextBlock>
+                                        </StackPanel>
+                                    </ToggleButton>
+
+                                    <Line Height="40" Stroke="#D5D6D8" StrokeThickness="2" X1="0" Y1="10" X2="0" Y2="30" Margin="8,0,8,0" />
+
+                                    <!--撤销-->
+                                    <Button Name="UndoBtn" Style="{StaticResource LightButtonStyle}" BorderThickness="0"  Width="40" Height="40" IsEnabled="{Binding CanUndo,Mode=OneWay}" Click="UndoBtn_Click"
+                                    Background="Transparent">
+                                        <Path x:Name="UndoPath" IsEnabled="{Binding CanUndo,Mode=OneWay}">
+                                            <Path.Style>
+                                                <Style TargetType="Path">
+                                                    <Style.Triggers>
+                                                        <Trigger Property="IsEnabled" Value="False">
+                                                            <Setter Property="Fill" Value="LightGray"/>
+                                                        </Trigger>
+                                                        <Trigger Property="IsEnabled" Value="True">
+                                                            <Setter Property="Fill" Value="#43474D"/>
+                                                        </Trigger>
+                                                    </Style.Triggers>
+                                                </Style>
+                                            </Path.Style>
+                                            <Path.Data>
+                                                M1.03033 3.62131L0.5 4.15164L1.03033 4.68197L4.65164 8.30328L5.7123 7.24261L3.37132 4.90164H10.0607C11.5794 4.90164 12.8107 6.13285 12.8107 
+                                7.65164C12.8107 9.17042 11.5794 10.4016 10.0607 10.4016H2.56066V11.9016H10.0607C12.4079 11.9016 14.3107 9.99885 14.3107 7.65164C14.3107 
+                                5.30443 12.4079 3.40164 10.0607 3.40164H3.37132L5.7123 1.06066L4.65164 0L1.03033 3.62131Z
+                                            </Path.Data>
+                                        </Path>
+                                    </Button>
+                                    <!--重做-->
+                                    <Button Style="{StaticResource LightButtonStyle}" BorderThickness="0" Width="40" Height="40" Margin="10,0,0,0"  IsEnabled="{Binding CanRedo,Mode=OneWay}" Click="RedoBtn_Click"
+                                    Background="Transparent">
+                                        <Path IsEnabled="{Binding CanRedo,Mode=OneWay}">
+                                            <Path.Resources>
+                                                <Style TargetType="Path">
+                                                    <Style.Triggers>
+                                                        <Trigger Property="IsEnabled" Value="False">
+                                                            <Setter Property="Fill" Value="LightGray"/>
+                                                        </Trigger>
+                                                        <Trigger Property="IsEnabled" Value="True">
+                                                            <Setter Property="Fill" Value="#43474D"/>
+                                                        </Trigger>
+                                                    </Style.Triggers>
+                                                </Style>
+                                            </Path.Resources>
+                                            <Path.Data>
+                                                M13.7802 3.62131L14.3105 4.15164L13.7802 4.68197L10.1589 8.30328L9.09825 7.24261L11.4392 4.90164H4.74989C3.2311 4.90164 1.99989 6.13285 
+                                1.99989 7.65164C1.99989 9.17042 3.2311 10.4016 4.74989 10.4016H12.2499V11.9016H4.74989C2.40268 11.9016 0.499887 9.99885 0.499887 
+                                7.65164C0.499887 5.30443 2.40268 3.40164 4.74989 3.40164H11.4392L9.09825 1.06066L10.1589 0L13.7802 3.62131Z
+                                            </Path.Data>
+                                        </Path>
+                                    </Button>
+                                </StackPanel>
+                            </Border>
+                        </Grid>
+                    </Border>
 
                     <Grid Grid.Row="1">
                         <Grid.ColumnDefinitions>

+ 285 - 13
compdfkit_demo_windows/compdfkit/compdfkit/MainWindow.xaml.cs

@@ -1,6 +1,11 @@
 using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using compdfkit_tools.Data;
+using compdfkit_tools.Edit;
 using compdfkit_tools.Helper;
 using compdfkit_tools.PDFControl;
+using ComPDFKitViewer;
+using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
@@ -29,6 +34,11 @@ namespace compdfkit
         private PDFViewControl passwordViewer;
         private PDFViewControl pdfViewControl = new PDFViewControl();
         private CPDFAnnotationControl pdfAnnotationControl = null;
+        private UIElement pdfEditControl = null;
+        /// <summary>
+        /// The last edit object
+        /// </summary>
+        private PDFEditEvent lastPDFEditEvent = null;
 
         private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
 
@@ -41,6 +51,7 @@ namespace compdfkit
 
         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
+            pdfAnnotationControl = new CPDFAnnotationControl();
             LoadDefaultDocument();
             BindZoomLevel();
         }
@@ -149,7 +160,7 @@ namespace compdfkit
                 ((CPDFBookmarkControl)currentBotaTool).InitWithPDFViewer(pdfViewControl.PDFView);
                 ((CPDFBookmarkControl)currentBotaTool).LoadBookmark();
             }
-
+            pdfAnnotationControl.SetPDFViewer(pdfViewControl.PDFView);
             ViewSettingBtn.IsChecked = false;
             PropertyContainer.Child = null;
             PropertyContainer.Visibility = Visibility.Collapsed;
@@ -200,7 +211,6 @@ namespace compdfkit
             }
         }
 
-
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
@@ -488,6 +498,10 @@ namespace compdfkit
             PropertyContainer.Width = 260;
             PropertyContainer.Child = properytPanel;
             PropertyContainer.Visibility = visible;
+            if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
+            {
+                RightPanelButton.IsChecked = false;
+            }
         }
 
         private void RightPanelButton_Click(object sender, RoutedEventArgs e)
@@ -497,7 +511,18 @@ namespace compdfkit
             {
                 if (toggleButton.IsChecked == true)
                 {
-                    ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                    if (currentMode == "Annotation")
+                    {
+                        ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                    }
+                    else if (currentMode == "Edit")
+                    {
+                        ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
+                    }
+                    else
+                    {
+                        ExpandRightPropertyPanel(null, Visibility.Visible);
+                    }
                     if ((bool)ViewSettingBtn.IsChecked)
                     {
                         ViewSettingBtn.IsChecked = false;
@@ -510,50 +535,297 @@ namespace compdfkit
             }
         }
 
+
+
         /// <summary>
-        /// 每一项退出时执行操作
-        /// 每一项进入时执行操作
+        /// Actions performed when switching modes:
+        /// Separated into actions performed upon entering and exiting the mode.
         /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             if (isFirstLoad)
             {
                 isFirstLoad = false;
-                return; 
+                return;
             }
 
             var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
             switch (currentMode)
             {
                 case "Viewer":
-                    
+
                     break;
+                //Behavior when exit Edit mode
+                // Clear the ToolBar
+                // Collapse the ToolBar
+                // Clear And Collapse the property panel.
                 case "Annotation":
-                    ToolBarContainer.Visibility = Visibility.Collapsed;
+                    AnnotationBarControl.Visibility = Visibility.Collapsed;
+                    AnnotationBarControl.ClearAllToolState();
+                    ExpandRightPropertyPanel(null, Visibility.Collapsed);
+
                     break;
+
+                // Behavior when exit Edit mode:
+                // Collapsed the ToolBar
+                // Set the mode to allow editing None
+                // Set the mouse mode to PanTool
+                // Reload Document
+                // Unsubscribe click event.
+                // Clear And Collapse the property panel.
                 case "Edit":
-                    ToolBarContainer.Visibility = Visibility.Collapsed;
+                    PDFEditTool.Visibility = Visibility.Collapsed;
+                    pdfViewControl.PDFView?.SetShowLink(true);
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
+                    pdfViewControl.PDFView?.ReloadDocument();
+
+                    pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
+                    ExpandRightPropertyPanel(null, Visibility.Collapsed);
                     break;
                 default:
                     break;
             }
 
+            // Behavior when switching to Viewer mode:
+            // Hide the ToolBar
             if ((string)item.Content == "Viewer")
             {
-                
+                ToolBarContainer.Visibility = Visibility.Collapsed;
             }
+
+            // Behavior when switching to Annotation mode:
+            // Show the ToolBar
+            // Show the AnnotationBar
             else if ((string)item.Content == "Annotation")
             {
                 ToolBarContainer.Visibility = Visibility.Visible;
+                AnnotationBarControl.Visibility = Visibility.Visible;
             }
+
+            // Behavior when switching to Edit mode:
+            // Show the ToolBar
+            // Show the EditBar
+            // Set the mode to allow editing of both text and images
+            // Set the mouse mode to PDFEdit
+            // Reload Document
             else if ((string)item.Content == "Edit")
             {
                 ToolBarContainer.Visibility = Visibility.Visible;
-            }
+                PDFEditTool.Visibility = Visibility.Visible;
+                pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
+                pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                pdfViewControl.PDFView?.ReloadDocument();
 
+                pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
+            }
             currentMode = (string)item.Content;
         }
+
+        #region Annotation Mode
+
+        private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            CPDFAnnotationType[] annotationProperties = { CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout, CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText, CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square, CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link, CPDFAnnotationType.Audio };
+            AnnotationBarControl.InitAnnotationBar(annotationProperties);
+            AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
+            AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
+            AnnotationBarControl.UndoRedoEvent += AnnotationBarControl_UndoRedoEvent;
+        }
+
+        private void AnnotationBarControl_UndoRedoEvent(object sender, string e)
+        {
+            if (pdfViewControl != null && pdfViewControl.PDFView != null)
+            {
+                if (e == "Undo")
+                {
+                    pdfViewControl.PDFView.UndoManager?.Undo();
+                }
+                else
+                {
+                    pdfViewControl.PDFView.UndoManager?.Redo();
+                }
+            }
+        }
+
+        private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
+        {
+            ToggleButton toggleButton = sender as ToggleButton;
+            if (toggleButton != null)
+            {
+                if (toggleButton.IsChecked == true)
+                {
+                    if (pdfAnnotationControl != null)
+                    {
+                        ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                        if ((bool)ViewSettingBtn.IsChecked)
+                        {
+                            ViewSettingBtn.IsChecked = false;
+                        }
+                    }
+                }
+                else
+                {
+                    ExpandRightPropertyPanel(null, Visibility.Collapsed);
+                }
+            }
+        }
+
+        private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
+        {
+            pdfAnnotationControl.LoadAnnotationPanel(e);
+            if (e != CPDFAnnotationType.Audio)
+            {
+                ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                RightPanelButton.IsChecked = true;
+            }
+        }
+
+        private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
+        {
+            AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
+            AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
+        }
+        #endregion
+
+        #region Edit Mode
+        /// <summary>
+        ///  Clear the selected state of editing-related buttons.
+        /// </summary>
+        private void ClearPDFEditState(ToggleButton ignoreBtn = null)
+        {
+            List<ToggleButton> clearBtnList = new List<ToggleButton>()
+            {
+                PDFTextEditButton,
+                PDFImageEditButton
+            };
+
+            foreach (ToggleButton item in clearBtnList)
+            {
+                if (ignoreBtn == item)
+                {
+                    continue;
+                }
+                item.IsChecked = false;
+            }
+        }
+
+        private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
+        {
+            ToggleButton senderBtn = sender as ToggleButton;
+            if (senderBtn != null && pdfViewControl != null)
+            {
+                ClearPDFEditState(senderBtn);
+                if (senderBtn.IsChecked == true)
+                {
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                    pdfViewControl.PDFView?.ReloadDocument();
+                }
+                else
+                {
+                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                    pdfViewControl.PDFView?.ReloadDocument();
+                }
+            }
+        }
+
+        private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
+        {
+            ToggleButton senderBtn = sender as ToggleButton;
+            if (senderBtn != null && pdfViewControl != null)
+            {
+                senderBtn.IsChecked = false;
+                OpenFileDialog openFileDialog = new OpenFileDialog();
+                openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
+                if (openFileDialog.ShowDialog() == true)
+                {
+                    ClearPDFEditState(senderBtn);
+                    pdfViewControl.PDFView?.ClearSelectPDFEdit();
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                    pdfViewControl.PDFView?.ReloadDocument();
+                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
+                    pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
+                }
+            }
+        }
+
+        private void UndoBtn_Click(object sender, RoutedEventArgs e)
+        {
+            if (pdfViewControl != null && pdfViewControl.PDFView != null)
+            {
+                pdfViewControl.PDFView.UndoManager?.Undo();
+            }
+        }
+
+        private void RedoBtn_Click(object sender, RoutedEventArgs e)
+        {
+            if (pdfViewControl != null && pdfViewControl.PDFView != null)
+            {
+                pdfViewControl.PDFView.UndoManager?.Redo();
+            }
+        }
+
+        /// <summary>
+        /// Text and Image Selected Event
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
+        {
+            lastPDFEditEvent = e;
+            ViewSettingBtn.IsChecked = false;
+            if (e == null)
+            {
+                pdfEditControl = null;
+                PropertyContainer.Child = pdfEditControl;
+                return;
+            }
+            if (Mouse.RightButton == MouseButtonState.Pressed)
+            {
+                return;
+            }
+            if (e.EditType == CPDFEditType.EditText)
+            {
+                PDFTextEditControl textEditControl = new PDFTextEditControl();
+                textEditControl.SetPDFTextEditData(e);
+                pdfEditControl = textEditControl as UIElement;
+                PropertyContainer.Child = pdfEditControl;
+                return;
+            }
+
+            if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
+            {
+                UIElement pageView = sender as UIElement;
+                if (pageView != null)
+                {
+                    pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp; ;
+                }
+                return;
+            }
+        }
+
+        private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            UIElement pageView = sender as UIElement;
+            if (pageView != null)
+            {
+                pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
+            }
+            if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
+            {
+                PDFImageEditControl imageEditControl = new PDFImageEditControl();
+                imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
+                imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
+                pdfEditControl = imageEditControl as UIElement;
+                PropertyContainer.Child = pdfEditControl;
+            }
+        }
+        #endregion
     }
 }

+ 1 - 3
compdfkit_demo_windows/compdfkit/edit-ctrl-demo/MainWindow.xaml

@@ -380,9 +380,7 @@
 
                     </StackPanel>
 
-                    <Border Grid.Row="1" Name="BotaToolContainer">
-
-                    </Border>
+                    <Border Grid.Row="1" Name="BotaToolContainer"></Border>
                 </Grid>
 
                 <!--拖动调节控件大小-->

+ 0 - 2
compdfkit_demo_windows/compdfkit/edit-ctrl-demo/MainWindow.xaml.cs

@@ -768,7 +768,6 @@ namespace edit_ctrl_demo
             {
 
             }
-
         }
 
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
@@ -901,7 +900,6 @@ namespace edit_ctrl_demo
         /// <summary>
         /// 文字编辑右键菜单
         /// </summary>
-
         private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
         {
             editCommand.PopupMenu = new ContextMenu();