Sfoglia il codice sorgente

compdfkit(win) - 注释快捷键

liuaoran 1 anno fa
parent
commit
e021cac75f

+ 75 - 5
Demo/Examples/Annotations/MainWindow.xaml

@@ -16,8 +16,78 @@
                 <ResourceDictionary Source="pack://application:,,,/Compdfkit_Tools;component/Asset/Styles/ButtonStyle.xaml"></ResourceDictionary>
                 <ResourceDictionary Source="pack://application:,,,/Compdfkit_Tools;component/Asset/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
+            <!-- Shortcut -->
+            <RoutedUICommand x:Key="Open" Text="Open"/>
+            <RoutedUICommand x:Key="Save" Text="Right rotate"/>
+            <RoutedUICommand x:Key="SaveAs" Text="Delete"/>
+            <RoutedUICommand x:Key="Undo" Text="Undo"/>
+            <RoutedUICommand x:Key="Redo" Text="Redo"/>
+            <RoutedUICommand x:Key="ControlLeftPanel" Text="Control left panel"/>
+            <RoutedUICommand x:Key="ControlRightPanel" Text="Control right panel"/>
+            <RoutedUICommand x:Key="GoToBookmark" Text="Go to bookmark"></RoutedUICommand>
+            <RoutedUICommand x:Key="GoToOutline" Text="Go to outline"></RoutedUICommand>
+            <RoutedUICommand x:Key="GoToThumbnail" Text="Go to thumbnail"></RoutedUICommand>
+            <RoutedUICommand x:Key="GoToAnnotationList" Text="Go to annotation list"></RoutedUICommand>
+            <RoutedUICommand x:Key="GoToSearch" Text="Go to search"></RoutedUICommand>
+            <RoutedUICommand x:Key="ScaleAdd" Text="Scale add"></RoutedUICommand>
+            <RoutedUICommand x:Key="ScaleSubtract" Text="Scale reduce"></RoutedUICommand>
+            <RoutedUICommand x:Key="DisplaySettings" Text="Display settings"></RoutedUICommand>
+            <RoutedUICommand x:Key="DocumentInfo" Text="Document infomation"></RoutedUICommand>
+            <RoutedUICommand x:Key="Highlight" Text="Highlight"></RoutedUICommand>
+            <RoutedUICommand x:Key="Underline" Text="Underline"></RoutedUICommand>
+            <RoutedUICommand x:Key="Strikeout" Text="Strikeout"></RoutedUICommand>
+            <RoutedUICommand x:Key="Squiggly" Text="Squiggly"></RoutedUICommand>
         </ResourceDictionary>
     </Window.Resources>
+ 
+    
+    
+    <Window.CommandBindings>
+        <CommandBinding Command="{StaticResource Open}" Executed="CommandBinding_Executed_Open"/>
+        <CommandBinding Command="{StaticResource Save}" Executed="CommandBinding_Executed_Save"/>
+        <CommandBinding Command="{StaticResource SaveAs}" Executed="CommandBinding_Executed_SaveAs"/>
+        <CommandBinding Command="{StaticResource Undo}" Executed="CommandBinding_Executed_Undo"/>
+        <CommandBinding Command="{StaticResource Redo}" Executed="CommandBinding_Executed_Redo"/>
+        <CommandBinding Command="{StaticResource ControlLeftPanel}" Executed="CommandBinding_Executed_ControlLeftPanel"></CommandBinding>
+        <CommandBinding Command="{StaticResource ControlRightPanel}" Executed="CommandBinding_Executed_ControlRightPanel"></CommandBinding>
+        <CommandBinding Command="{StaticResource GoToBookmark}" Executed="CommandBinding_Executed_Bookmark"></CommandBinding>
+        <CommandBinding Command="{StaticResource GoToOutline}" Executed="CommandBinding_Executed_Outline"></CommandBinding>
+        <CommandBinding Command="{StaticResource GoToThumbnail}" Executed="CommandBinding_Executed_Thumbnail"></CommandBinding>
+        <CommandBinding Command="{StaticResource GoToAnnotationList}" Executed="CommandBinding_Executed_Annotation"></CommandBinding>
+        <CommandBinding Command="{StaticResource GoToSearch}" Executed="CommandBinding_Executed_Search"></CommandBinding>
+        <CommandBinding Command="{StaticResource ScaleAdd}" Executed="CommandBinding_Executed_ScaleAdd"></CommandBinding>
+        <CommandBinding Command="{StaticResource ScaleSubtract}" Executed="CommandBinding_Executed_ScaleSubtract"></CommandBinding>
+        <CommandBinding Command="{StaticResource DisplaySettings}" Executed="CommandBinding_Executed_DisplaySettings"></CommandBinding>
+        <CommandBinding Command="{StaticResource DocumentInfo}" Executed="CommandBinding_Executed_DocumentInfo"></CommandBinding>
+        <CommandBinding Command="{StaticResource Highlight}" Executed="CommandBinding_Executed_Highlight"></CommandBinding>
+        <CommandBinding Command="{StaticResource Underline}" Executed="CommandBinding_Executed_Underline"></CommandBinding>
+        <CommandBinding Command="{StaticResource Strikeout}" Executed="CommandBinding_Executed_Strikeout"></CommandBinding>
+        <CommandBinding Command="{StaticResource Squiggly}" Executed="CommandBinding_Executed_Squiggly"></CommandBinding>
+    </Window.CommandBindings>
+
+    <Window.InputBindings>
+        <KeyBinding Key="O" Modifiers="Control" Command="{StaticResource Open}"/>
+        <KeyBinding Key="S" Modifiers="Control" Command="{StaticResource Save}"/>
+        <KeyBinding Key="S" Modifiers="Control+Shift" Command="{StaticResource SaveAs}"/>
+        <KeyBinding Key="Z" Modifiers="Control" Command="{StaticResource Undo}"/>
+        <KeyBinding Key="Y" Modifiers="Control" Command="{StaticResource Redo}"/>
+        <KeyBinding Key="F4" Command="{StaticResource ControlLeftPanel}"/>
+        <KeyBinding Key="F4" Modifiers="Control" Command="{StaticResource ControlRightPanel}"/>
+        <KeyBinding Key="B" Modifiers="Control" Command="{StaticResource GoToBookmark}"></KeyBinding>
+        <KeyBinding Key="O" Modifiers="Control+Shift" Command="{StaticResource GoToOutline}"></KeyBinding>
+        <KeyBinding Key="T" Modifiers="Control" Command="{StaticResource GoToThumbnail}"></KeyBinding>
+        <KeyBinding Key="A" Modifiers="Control" Command="{StaticResource GoToAnnotationList}"></KeyBinding>
+        <KeyBinding Key="F" Modifiers="Control" Command="{StaticResource GoToSearch}"></KeyBinding>
+        <KeyBinding Key="Add" Modifiers="Control" Command="{StaticResource ScaleAdd}"></KeyBinding>
+        <KeyBinding Key="Subtract" Modifiers="Control" Command="{StaticResource ScaleSubtract}"></KeyBinding>
+        <KeyBinding Key="D" Modifiers="Control" Command="{StaticResource DisplaySettings}"></KeyBinding>
+        <KeyBinding Key="I" Modifiers="Control" Command="{StaticResource DocumentInfo}"></KeyBinding>
+        <KeyBinding Key="H" Modifiers="Control+Alt" Command="{StaticResource Highlight}"></KeyBinding>
+        <KeyBinding Key="U" Modifiers="Control+Alt" Command="{StaticResource Underline}"></KeyBinding>
+        <KeyBinding Key="Q" Modifiers="Control+Alt" Command="{StaticResource Squiggly}"></KeyBinding>
+        <KeyBinding Key="S" Modifiers="Control+Alt" Command="{StaticResource Strikeout}"></KeyBinding>
+    </Window.InputBindings>
+
     <Grid>
         <Grid>
             <Grid.RowDefinitions>
@@ -79,8 +149,8 @@
                             <ToolTip Content="Save"></ToolTip>
                         </Button.ToolTip>
                     </Button>
- 
-                    <ToggleButton Name="ToolExpandBtn" Margin="13,0,0,0" BorderThickness="0" Width="30" Height="30" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="ToolExpand_Click">
+
+                    <ToggleButton Name="LeftToolPanelButton" Margin="13,0,0,0" BorderThickness="0" Width="30" Height="30" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="LeftToolPanelButton_Click">
                         <ToggleButton.Content>
                             <Path Fill="#43474D" Width="30" Height="30">
                                 <Path.Data>
@@ -119,8 +189,8 @@
 
                     <cpdftools:CPDFScalingControl x:Name="CPDFSaclingControl"></cpdftools:CPDFScalingControl>
                 </StackPanel>
- 
-                <ComboBox Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
+
+                <ComboBox Name="ModeComboBox" Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
                     <ComboBoxItem IsSelected="True" Tag="Viewer">Viewer</ComboBoxItem>
                     <ComboBoxItem IsSelected="True" Tag="Annotation">Annotation</ComboBoxItem>
                 </ComboBox>
@@ -144,7 +214,7 @@
                         </Button.ToolTip>
                     </Button>
 
-                    <ToggleButton  x:Name="AnnotationBarBtn" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="AnnotationBarControl_Click">
+                    <ToggleButton  x:Name="RightPanelButton" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="RightPanelButton_Click">
                         <ToggleButton.Content>
                             <Path Fill="#43474D" Width="30" Height="30">
                                 <Path.Data>

+ 213 - 24
Demo/Examples/Annotations/MainWindow.xaml.cs

@@ -217,7 +217,7 @@ namespace Annotations
             PropertyContainer.Visibility = visible;
             if (visible == Visibility.Collapsed || visible == Visibility.Hidden)
             {
-                AnnotationBarBtn.IsChecked = false;
+                RightPanelButton.IsChecked = false;
             }
         }
 
@@ -290,8 +290,7 @@ namespace Annotations
                                     pdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
                                     pdfViewControl.PDFView.SetToolParam(highLightArgs);
                                     pdfViewControl.PDFView.SetMouseMode(oldMode);
-                                }
-
+                                } 
                             };
 
                             e.PopupMenu.Items.Add(highLightMenu);
@@ -597,36 +596,39 @@ namespace Annotations
             return standardZoom / 100;
         }
 
-        private void ToolExpand_Click(object sender, RoutedEventArgs e)
+        private void ControlLeftPanel()
         {
-            ToggleButton expandBtn = sender as ToggleButton;
-            if (expandBtn != null)
+            if (LeftToolPanelButton != null)
             {
-                bool isExpand = expandBtn.IsChecked == true;
+                bool isExpand = LeftToolPanelButton.IsChecked == true;
                 ExpandLeftPanel(isExpand);
             }
         }
 
+        private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
+        {
+            ControlLeftPanel();
+        }
+
         private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
         {
             ExpandLeftPanel(true);
             BotaSideTool.SelectBotaTool(BOTATools.Search);
         }
 
-        private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
+        private void ShowViewSettings()
         {
-            ToggleButton toggleButton = sender as ToggleButton;
-            if (toggleButton != null)
+            if (ViewSettingBtn != null)
             {
-                if (toggleButton.IsChecked == true)
+                if (ViewSettingBtn.IsChecked == true)
                 {
                     CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
                     displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
                     PropertyContainer.Child = displayPanel;
                     PropertyContainer.Visibility = Visibility.Visible;
-                    if ((bool)AnnotationBarBtn.IsChecked)
+                    if ((bool)RightPanelButton.IsChecked)
                     {
-                        AnnotationBarBtn.IsChecked = false;
+                        RightPanelButton.IsChecked = false;
                     }
                 }
                 else
@@ -637,6 +639,11 @@ namespace Annotations
             }
         }
 
+        private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
+        {
+            ShowViewSettings();
+        }
+
         private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
         {
             PasswordUI.Visibility = Visibility.Collapsed;
@@ -650,7 +657,7 @@ namespace Annotations
             PopupBorder.Visibility = Visibility.Collapsed;
         }
 
-        private void OpenFile_Click(object sender, RoutedEventArgs e)
+        private void OpenFile()
         {
             string filePath = CommonHelper.GetFilePathOrEmpty();
             if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
@@ -687,18 +694,22 @@ namespace Annotations
             }
         }
 
+        private void OpenFile_Click(object sender, RoutedEventArgs e)
+        {
+            OpenFile();
+        }
+
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
             pdfViewControl.PDFView.UndoManager.CanSave = false;
         }
 
-        private void AnnotationBarControl_Click(object sender, RoutedEventArgs e)
-        {
-            ToggleButton toggleButton = sender as ToggleButton;
-            if (toggleButton != null)
+        private void ControlRightPanel()
+        { 
+            if (RightPanelButton != null)
             {
-                if (toggleButton.IsChecked == true)
+                if (RightPanelButton.IsChecked == true)
                 {
                     if (pdfAnnotationControl != null)
                     {
@@ -716,6 +727,11 @@ namespace Annotations
             }
         }
 
+        private void RightPanelButton_Click(object sender, RoutedEventArgs e)
+        {
+            ControlRightPanel();
+        }
+
         private void EditLink_Click(object sender, RoutedEventArgs e)
         {
             PropertyContainer.Visibility = Visibility.Visible;
@@ -758,7 +774,7 @@ namespace Annotations
         {
             pdfAnnotationControl.AnnotationCancel();
             ExpandRightPropertyPanel(null, Visibility.Collapsed);
-            AnnotationBarBtn.IsChecked = false;
+            RightPanelButton.IsChecked = false;
             ViewSettingBtn.IsChecked = false;
         }
 
@@ -768,7 +784,7 @@ namespace Annotations
             if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
             {
                 ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
-                AnnotationBarBtn.IsChecked = true;
+                RightPanelButton.IsChecked = true;
             }
         }
 
@@ -784,8 +800,7 @@ namespace Annotations
         }
 
         private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
-        {
-
+        { 
             if (e.Key == "Zoom")
             {
                 CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
@@ -794,6 +809,31 @@ namespace Annotations
         #endregion
 
         #region Save file
+        /// <summary>
+        /// Save the file to another PDF file.
+        /// </summary>
+        public void SaveAsFile()
+        {
+            {
+                if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
+                {
+                    CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
+                    SaveFileDialog saveDialog = new SaveFileDialog();
+                    saveDialog.Filter = "(*.pdf)|*.pdf";
+                    saveDialog.DefaultExt = ".pdf";
+                    saveDialog.OverwritePrompt = true;
+
+                    if (saveDialog.ShowDialog() == true)
+                    {
+                        pdfDoc.WriteToFilePath(saveDialog.FileName);
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// Save the file in the current path.
+        /// </summary>
         private void SaveFile()
         {
             if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
@@ -836,7 +876,7 @@ namespace Annotations
                 ToolBarContainer.Visibility = Visibility.Collapsed;
                 ExpandRightPropertyPanel(null, Visibility.Collapsed);
                 pdfAnnotationControl.AnnotationCancel();
-                AnnotationBarBtn.IsChecked = false;
+                RightPanelButton.IsChecked = false;
                 if (pdfViewControl != null && pdfViewControl.PDFView != null)
                 {
                     pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
@@ -877,5 +917,154 @@ namespace Annotations
         }
 
         #endregion
+
+        #region Shortcut
+        private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
+        {
+            OpenFile();
+        }
+
+        private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (CanSave)
+            {
+                SaveFile();
+            }
+        }
+
+        private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
+        {
+            SaveAsFile();
+        }
+
+        private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (pdfViewControl != null && pdfViewControl.PDFView != null && CanUndo)
+            {
+                pdfViewControl.PDFView.UndoManager?.Undo();
+            }
+        }
+
+        private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (pdfViewControl != null && pdfViewControl.PDFView != null && CanRedo)
+            {
+                pdfViewControl.PDFView.UndoManager?.Redo();
+            }
+        }
+
+        private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
+        {
+            LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
+            ControlLeftPanel();
+        }
+
+        private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
+        {
+            RightPanelButton.IsChecked = !RightPanelButton.IsChecked;
+            ControlRightPanel();
+        }
+
+        private void CommandBinding_Executed_Highlight(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (ModeComboBox.SelectedIndex == 1)
+            {
+                AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Highlight);
+            }
+        }
+
+        private void CommandBinding_Executed_Underline(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (ModeComboBox.SelectedIndex == 1)
+            {
+                AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Underline);
+            }
+        }
+
+        private void CommandBinding_Executed_Strikeout(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (ModeComboBox.SelectedIndex == 1)
+            {
+                AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Strikeout);
+            }
+        }
+
+        private void CommandBinding_Executed_Squiggly(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (ModeComboBox.SelectedIndex == 1)
+            {
+                AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Squiggly);
+            }
+        }
+
+        private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
+        {
+            ExpandLeftPanel(true);
+            LeftToolPanelButton.IsChecked = true;
+            BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
+        }
+
+        private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
+        {
+            ExpandLeftPanel(true);
+            LeftToolPanelButton.IsChecked = true;
+            BotaSideTool.SelectBotaTool(BOTATools.Outline);
+        }
+
+        private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
+        {
+            ExpandLeftPanel(true);
+            LeftToolPanelButton.IsChecked = true;
+            BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
+        }
+
+        private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
+        {
+            ExpandLeftPanel(true);
+            LeftToolPanelButton.IsChecked = true;
+            BotaSideTool.SelectBotaTool(BOTATools.Annotation);
+        }
+
+        private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
+        {
+            ExpandLeftPanel(true);
+            LeftToolPanelButton.IsChecked = true;
+            BotaSideTool.SelectBotaTool(BOTATools.Search);
+        }
+
+        private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
+        {
+            double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
+            pdfViewControl.PDFView?.Zoom(newZoom);
+        }
+
+        private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
+        {
+            double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
+            pdfViewControl.PDFView?.Zoom(newZoom);
+        }
+
+        private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
+        {
+            ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
+            ShowViewSettings();
+        }
+
+        private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
+        {
+            if (PopupBorder.Visibility != Visibility.Visible)
+            {
+                PasswordUI.Visibility = Visibility.Collapsed;
+                FileInfoUI.Visibility = Visibility.Visible;
+                FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
+                PopupBorder.Visibility = Visibility.Visible;
+            }
+            else
+            {
+                FileInfoUI.Visibility = Visibility.Collapsed;
+                PopupBorder.Visibility = Visibility.Collapsed;
+            }
+        }
+        #endregion
     }
 }

+ 40 - 3
Demo/Examples/Compdfkit_Tools/Common/BarControl/CPDFAnnotationBarControl.xaml.cs

@@ -1,5 +1,6 @@
 using Compdfkit_Tools.Data;
 using System;
+using System.Collections.Generic;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
@@ -218,9 +219,9 @@ namespace Compdfkit_Tools.PDFControl
                 canvas.Children.Add(path);
             }
 
-            else if (toggleButton.Tag.ToString()==CPDFAnnotationType.Image.ToString())
+            else if (toggleButton.Tag.ToString() == CPDFAnnotationType.Image.ToString())
             {
-              
+
                 annotationGeometry = Geometry.Parse("M18.75,3.25 L18.75,16.75 L1.25,16.75 L1.25,3.25 L18.75,3.25 Z M17.25,4.75 L2.75,4.75 L2.75,13.209 L5.79495643,10 L10.0642824,13.5 L12.3718478,11.0677556 L17.144,15.25 L17.25,15.25 L17.25,4.75 Z M14.5,6 C15.3284271,6 16,6.67157288 16,7.5 C16,8.32842712 15.3284271,9 14.5,9 C13.6715729,9 13,8.32842712 13,7.5 C13,6.67157288 13.6715729,6 14.5,6 Z");
                 Path imagePath = new Path
                 {
@@ -295,7 +296,7 @@ namespace Compdfkit_Tools.PDFControl
                 toggleButton.ToolTip = toggleButton.Tag.ToString();
                 Grid.SetColumn(toggleButton, annotationCounter++);
                 AnnotationGrid.Children.Add(toggleButton);
-            } 
+            }
         }
 
         public void ClearAllToolState()
@@ -336,6 +337,42 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
 
+        private ToggleButton FindToggleButtonByTag(DependencyObject parent, string tag)
+        {
+            var count = VisualTreeHelper.GetChildrenCount(parent);
+
+            for (var i = 0; i < count; i++)
+            {
+                var child = VisualTreeHelper.GetChild(parent, i);
+
+                if (child is ToggleButton toggleButton && toggleButton.Tag != null && toggleButton.Tag.ToString() == tag)
+                {
+                    return toggleButton;
+                }
+                else
+                {
+                    var result = FindToggleButtonByTag(child, tag);
+                    if (result != null)
+                    {
+                        return result;
+                    }
+                }
+            }
+            return null;
+        }
+
+        public void SetAnnotationType(CPDFAnnotationType annotationType)
+        { 
+            ToggleButton toggleButton = FindToggleButtonByTag(this, annotationType.ToString());
+            if (toggleButton != null)
+            {
+                toggleButton.IsChecked = true;
+                ClearToolState(toggleButton);
+                AnnotationPropertyChanged?.Invoke(toggleButton, CPDFAnnotationDictionary.GetAnnotationFromTag[toggleButton.Tag.ToString()]);
+                CurrentMode = toggleButton.Tag.ToString();
+            } 
+        }
+
         public void InitAnnotationBar(CPDFAnnotationType[] annotationProperties)
         {
             for (int i = 0; i < annotationProperties.Length; i++)

+ 1 - 17
Demo/Examples/Forms/MainWindow.xaml.cs

@@ -559,23 +559,7 @@ namespace Forms
 
         private void RightPanelButton_Click(object sender, RoutedEventArgs e)
         {
-            ToggleButton toggleButton = sender as ToggleButton;
-            if (toggleButton != null)
-            {
-                if (toggleButton.IsChecked == true)
-                {
-
-                    ExpandRightPropertyPanel(formPropertyControl, Visibility.Visible);
-                    if ((bool)ViewSettingBtn.IsChecked)
-                    {
-                        ViewSettingBtn.IsChecked = false;
-                    }
-                }
-                else
-                {
-                    ExpandRightPropertyPanel(null, Visibility.Collapsed);
-                }
-            }
+            ControlRightPanel();
         }
 
         private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

+ 1 - 0
Demo/Examples/PDFViewer/MainPage.xaml

@@ -72,6 +72,7 @@
         <KeyBinding Key="D" Modifiers="Control" Command="{StaticResource DisplaySettings}"></KeyBinding>
         <KeyBinding Key="I" Modifiers="Control" Command="{StaticResource DocumentInfo}"></KeyBinding>
     </UserControl.InputBindings>
+    
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="auto"></RowDefinition>

+ 1 - 1
Demo/Examples/Viewer/MainWindow.xaml

@@ -7,7 +7,7 @@
         xmlns:cpdftools="clr-namespace:Compdfkit_Tools.PDFControl;assembly=Compdfkit_Tools"
         xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common;assembly=Compdfkit_Tools"
         mc:Ignorable="d"
-        Title="Viewer_ComPDFKit" Height="720" Width="1080"  WindowStartupLocation="CenterScreen">
+        Title="Viewer_ComPDFKit 1.9.1" Height="720" Width="1080"  WindowStartupLocation="CenterScreen">
     <Window.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>

+ 5 - 0
Demo/Examples/Viewer/MainWindow.xaml.cs

@@ -726,5 +726,10 @@ namespace Viewer
             }
         }
         #endregion
+
+        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
+        {
+
+        }
     }
 }